如何消除mysql中的重复记录

时间:2012-03-05 09:38:15

标签: mysql

此查询:

  SELECT city_alias,population
    FROM `table_name`
   where state='NV' and city_type='P'
order by `population` DESC
   LIMIT 0, 5              


Las Vegas   70994
Las Vegas   70123
Las Vegas   64096
North Las Vegas 60589
Las Vegas   58794
Las Vegas   56300
Las Vegas   55416
North Las Vegas 53928
Las Vegas   51252
Las Vegas   50519
Las Vegas   49778
Las Vegas   49445
Henderson   47214
Henderson   47095
Las Vegas   46055
Las Vegas   45720
Reno            43566
Las Vegas   43072
North Las Vegas 40297
Las Vegas   39909

所以我应该得到

Las Vegas   70994
North Las Vegas 60589
Henderson   47214
Reno            43566

3 个答案:

答案 0 :(得分:1)

我希望它对您有用

Select from table_name Group by name Having Max(pop);

答案 1 :(得分:0)

您可以使用此查询

Select name from table_Name group by name

如果你想像这样使用id和popup

Select name,id,popup from table_Name group by id,popup,name

答案 2 :(得分:0)

在这种情况下使用DISTINCT ...

SELECT DISTINCT(city_alias), population FROM table_name where state='NV' and city_type='P' order by population DESC LIMIT 0, 5