Home > Software design >  How get first row from duplicate values mysql query
How get first row from duplicate values mysql query

Time:05-13

My table with value

id  ssid_no  end_date
1   5415345  18/12/2020
2   4656845  18/12/2020
3   8554511  01/05/2019

I want to make group but eliminite dublicate and select first id row. in example eliminate after group select id='1' row(1,2 row have dublicate select first one) and id= '3' row

CodePudding user response:

SELECT * FROM (SELECT id, ssid_no, end_date, ROW_NUMBER() OVER (PARTITION BY ssid_no ORDER BY end_date) AS rownumber FROM ssid_no) t WHERE t.rownumber = 1;

This will return the first row for each id.

  • Related