问题
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