get the row with the highest value in MySQL

后端 未结 3 622
后悔当初
后悔当初 2020-12-12 06:33

I want to get the highest value but group by another field on the same table ex:

seqid + fileid + name

1  |    1 | n1
2  |    1 | n2
3  |    2 | n3
         


        
3条回答
  •  时光说笑
    2020-12-12 07:09

    SELECT seqid, fileid, name
    FROM tbl JOIN (
        SELECT MAX(seqid) maxSeq, fileid fileid
        FROM tbl
        GROUP BY fileid
        ) tg ON tml.seqid = tg.maxSeq AND tbl.fileid = tg.fileid
    

提交回复
热议问题