I have a table that looks like this:
name | surname
------------------
John | John
Jessica | Madson
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?
Introduction to SQL DISTINCT operator Note that the DISTINCT only removes the duplicate rows from the result set. It doesn't delete duplicate rows in the table. If you want to select two columns and remove duplicates in one column, you should use the GROUP BY clause instead.
Try:
SELECT DISTINCT name, surname FROM table WHERE name LIKE '%j%' OR surname LIKE '%j%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With