I have the following query:
SELECT first, last, title, email, org
FROM people WHERE email <> ""
INTO OUTFILE 'C:/testfile.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
Which works. I need to select distinct emails (I don’t want multiple entries from the same email).
Would it work like?:
SELECT first, last, title, distinct(email), org
FROM people WHERE email <> ""
INTO OUTFILE 'C:/testfile.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
Which platform / version of SQL are you using? Typically this would be done with a group by statement. Something like:
The above will actually work with some platforms / versions of SQL but the “correct” (standard sql) way to do it would be as follows (of course if the other fields are different for same email you get undefined results):