SQL: How can I return the highest ranking record of similar records, based on one column value?

前端 未结 4 2044
無奈伤痛
無奈伤痛 2021-01-27 23:22

This seems like it should be easier than I\'m finding it. I have a table that contains both first and last names (specified by a type ID) and a frequency of how common the name

4条回答
  •  长情又很酷
    2021-01-27 23:53

    If you want top 2 for both first and last name, you can do UNION ALL.

    select name 
    FROM table
    where Nametype = 1
    order by FrequencyPercent desc
    limit 2
    UNION ALL
    select name 
    from table
    where nametype = 2
    order by FrequencyPercent desc
    limit2
    
    

提交回复
热议问题