Search code examples
sqlpostgresqlsql-order-bygreatest-n-per-group

how to select max score from duplicate mobile_number


enter image description here

how can I filter record 60122839991 with the highest score 95.3758 and return as below without duplicate phone number

enter image description here


Solution

  • Use distinct on:

    select distinct on (mobile_number) t.*
    from mytable t
    order by mobile_number, score desc