Delete repeated results from MySQL query

2019-02-26 00:02发布

A MySQL query retrieves:

totalpoints --  name 
55 -- John Doe
55 -- John Doe
55 -- John Doe
55 -- John Doe
55 -- John Doe
21 -- Jean London
21 -- Jean London
13 -- Mark Derry
13 -- Mark Derry
13 -- Mark Derry
13 -- Mark Derry
4 -- Lara Croft
1 -- Ryan Mirtle
1 -- Ryan Mirtle
1 -- Ryan Mirtle

I need to show in a php page just:

totalpoints --  name 
55 -- John Doe
21 -- Jean London
13 -- Mark Derry
4 -- Lara Croft
1 -- Ryan Mirtle

How can I get rid off the repeated results? Thanks a lot

标签: php mysql rows
5条回答
叼着烟拽天下
2楼-- · 2019-02-26 00:12

Please use DISTINCT keyword in your query to avoid duplicate entries

查看更多
放我归山
3楼-- · 2019-02-26 00:27

What about using DISTINCT? Seems pretty easy... But you actually tried to google it? ou would have found it in no time.

查看更多
疯言疯语
4楼-- · 2019-02-26 00:27
select name,totalpoints
from table
group by name
order by totalpoints desc
查看更多
萌系小妹纸
5楼-- · 2019-02-26 00:29
select distinct name,totalpoints from table
查看更多
干净又极端
6楼-- · 2019-02-26 00:39

Very easy. use following query:

SELECT totalpoints, name
FROM table_name
GROUP BY name
ORDER BY totalpoints DESC
查看更多
登录 后发表回答