How to select a limited amount of rows for each foreign key?

前端 未结 4 827
忘掉有多难
忘掉有多难 2021-01-06 10:19

I have this table:

id
feed_id
...

Let\'s say that I have 500 rows and I want to select 3 entries for each feed_id? And 50 as total limit.

4条回答
  •  一向
    一向 (楼主)
    2021-01-06 10:38

    Have you tried using a subselect and limit?

    Something like

    SELECT  *
    FROM    Table t
    WHERE   ID IN (SELECT ID FROM @Table WHERE FEED_ID = t.FEED_ID LIMIT 3)
    LIMIT 500
    

提交回复
热议问题