How to do equivalent of “limit distinct”?

后端 未结 2 1078
一向
一向 2021-01-06 19:27

How can I limit a result set to n distinct values of a given column(s), where the actual number of rows may be higher?

Input table:

client_i         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-06 19:38

    You can use a subselect

    select * from table where client_id in 
    (select distinct client_id from table order by client_id limit 5)
    

提交回复
热议问题