SQL - Remove Duplicate Results

孤街醉人 提交于 2020-01-11 00:57:29

问题


I have a table that looks like this:

name     | surname<br>
John     |  John<br>
Jessica  |  Madson<br>

I have a query like this:

SELECT * FROM table WHERE name LIKE '%j%' OR surname LIKE '%j%'

What I get:

John John
John John
Jessica Madson

What I want:

John John
Jessica Madson

How can I get rid of the duplicate results?


回答1:


Use DISTINCT:

SELECT DISTINCT name, surname
FROM yourtable
WHERE name LIKE '%j%' OR surname LIKE '%j%'



回答2:


Try:

SELECT DISTINCT name, surname FROM table WHERE name LIKE '%j%' OR surname LIKE '%j%'



回答3:


You could also use group by

SELECT name, surname
FROM yourtable
WHERE name LIKE '%j%' OR surname LIKE '%j%'
GROUP BY name, surname


来源:https://stackoverflow.com/questions/10659860/sql-remove-duplicate-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!