mySQL4.1 - using DISTINCT in WHERE ?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
winky3d
Forum Newbie
Posts: 9
Joined: Thu Apr 26, 2007 1:37 pm

mySQL4.1 - using DISTINCT in WHERE ?

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

swap the distinct for a GROUP BY email clause
winky3d
Forum Newbie
Posts: 9
Joined: Thu Apr 26, 2007 1:37 pm

Post by winky3d »

Great, thanks.
winky3d
Forum Newbie
Posts: 9
Joined: Thu Apr 26, 2007 1:37 pm

Post 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?
winky3d
Forum Newbie
Posts: 9
Joined: Thu Apr 26, 2007 1:37 pm

[SOLVED]

Post 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"
Post Reply