user7832
user7832

Reputation: 51

ignore duplicated rows in database

I have a csv file wich I have imported in a database in phpmyadmin, I need to write to a file a new csv file but ignoring duplicated emails, for example if my query finds these two rows :

41  Alain   Aiseng  [email protected]  DL MCI    

42  Alain   Aiseng  [email protected]  LNKD 05 14   

BOTH rows should be ignored in my new csv output. What should be the SQL query for this ?

Upvotes: 2

Views: 58

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1271211

You can generate a query for this (and then save the results to a file). The query is:

select t.*
from table t
group by name, email
having count(*) = 1;

The columns name and email correspond to whichever columns hold Alain Aiseng and [email protected].

Note that this uses a MySQL feature where column names do not have to be in the group by for an aggregation query. This is one case where this feature is totally safe to use, because the having clause specifies that only one row matches the condition.

Upvotes: 3

VJ Hil
VJ Hil

Reputation: 904

       select * from table 
       where email not in
       (select email from table group by email having count(*)>1)a;

Upvotes: 3

Related Questions