Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Remove the duplicate Results

Tags:

sql

duplicates

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?

like image 678
yturgun Avatar asked May 18 '12 21:05

yturgun


People also ask

How do I remove duplicates from one column in SQL?

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.


1 Answers

Try:

SELECT DISTINCT name, surname FROM table WHERE name LIKE '%j%' OR surname LIKE '%j%'
like image 108
Orbiting Eden Avatar answered Oct 17 '22 16:10

Orbiting Eden