get the row with the highest value in MySQL

后端 未结 3 639
后悔当初
后悔当初 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 06:56

    Describe exactly what you need, provide bigger table, and result table, also I dont get it what you mean at all highest value but group by another field, highest value of what column?

    in your result you mention 4|3|n5, why not 5|3|n5 if you say Highest ?

    ok so you edited it..

    looks fairly simple something like

         select seqid, filed,name from table t1 join 
    (select max(seqid) seqid from table group by fileid) as t2 on t2.seqid=t1.seqid
    

    if seqid is PK you dont need anything but PK i dont get why would you want to join on 2 fields instead of just PK

提交回复
热议问题