Page 1 of 1

mySQL4.1 - using DISTINCT in WHERE ?

Posted: Fri Apr 27, 2007 5:20 pm
by winky3d
I'm trying to retrieve all the columns in any rows that fall between a date range and have distinct emails...

Code: Select all

sql_query("SELECT  DISTINCT `email` FROM "._MY_TABLE." WHERE ts BETWEEN '$startdate' AND '$enddate'");
The above works, but only returns the email column for each row.

How can I can all the columns for each row?

thx.

Posted: Fri Apr 27, 2007 5:23 pm
by John Cartwright
swap the distinct for a GROUP BY email clause

Posted: Fri Apr 27, 2007 5:41 pm
by winky3d
Great, thanks.

Posted: Wed May 02, 2007 12:39 pm
by winky3d
Still having trouble...

This only returns one result:

Code: Select all

SELECT COUNT(*) FROM "._MY_TABLE." WHERE ts BETWEEN '$startdate' AND '$enddate' GROUP BY email HAVING COUNT(*) < 2
How can I return all the results where email is unique?

[SOLVED]

Posted: Wed May 02, 2007 1:19 pm
by winky3d
For the rest of us noobs... This works

Code: Select all

"SELECT email, COUNT(*) FROM "._MY_TABLE." WHERE ts BETWEEN '$startdate' AND '$enddate' GROUP BY email"