Reputation: 51
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
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
Reputation: 904
select * from table
where email not in
(select email from table group by email having count(*)>1)a;
Upvotes: 3