Combine two sql select queries (in postgres) with LIMIT statement

后端 未结 2 933
故里飘歌
故里飘歌 2021-01-01 09:34

I\'ve got a table and I want a query that returns the last 10 records created plus the record who\'s id is x.

I\'m trying to do -

SELECT * FROM cata         


        
相关标签:
2条回答
  • 2021-01-01 10:36

    This will give you records from 10th to 20th and should get you started.i will reply back with SQLfiddle

    SELECT *  
      FROM (SELECT ROW_NUMBER () OVER (ORDER BY cat_id) cat_row_no, a.* FROM catalog_productimage a where x=5)  
     WHERE cat_row_no > 10 and cat_row_no <20  
    
    0 讨论(0)
  • 2021-01-01 10:39

    Just checked that this will work:

    (SELECT * FROM catalog_productimage
    ORDER BY date_modified
    LIMIT 10)
    UNION
    SELECT * FROM catalog_productimage
    WHERE id=5;
    
    0 讨论(0)
提交回复
热议问题