MySQL Select rows on first occurrence of each unique value

后端 未结 5 1138
迷失自我
迷失自我 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:48

    Try this one,

    SELECT *
    FROM tableName a 
    INNER JOIN (
        SELECT cid, MIN(`time`) AS MinTime
        FROM tableName
        GROUP BY cid
    ) b 
    ON a.CID = B.cid AND a.time = b.MinTime
    

提交回复
热议问题