MySQL Select rows on first occurrence of each unique value

后端 未结 5 1156
迷失自我
迷失自我 2020-12-08 04:06

Let\'s say you have the following table (the column of interest here is cid):

+-----+-------+-------+-------+---------------------+-------------         


        
5条回答
  •  情深已故
    2020-12-08 04:40

    In MySQL 8, you would use window functions for this

    SELECT cid, pid, rid, clink, time, snippet
    FROM (
      SELECT t.*, ROW_NUMBER() OVER (PARTITION BY cid ORDER BY time) rn
      FROM t
    ) t
    WHERE rn = 1
    

提交回复
热议问题