Page 1 of 1

SQL to get Unique Email

Posted: Tue Mar 24, 2009 1:54 am
by ninethousandfeet
hello,
i allow my users to enter conversations with one another. if a new comment is posted in one of these conversations, then i would like all users involved to receive an email to let them know about the new comment. can i use SQL to query only the unique email addresses in a conversation? i tried LIMIT and that didn't work.
the way it stands now, users are sent an multiple emails (i only want each participating user to receive one email)...

SELECT testComment.email, testComment.comment_title FROM testComment WHERE testComment.comment_title = %s GROUP BY testComment.email

thank you!

Re: SQL to get Unique Email

Posted: Tue Mar 24, 2009 5:45 am
by sujithtomy
Hello,

Use DISTINCT keyword before fieldname

eg:

Code: Select all

SELECT DISTINCT email FROM table_name WHERE condition
Good Luck :)

Regards,
Sujith

Re: SQL to get Unique Email

Posted: Tue Mar 24, 2009 5:48 am
by jayshields
Please don't put links to your blog behind keywords.

Re: SQL to get Unique Email

Posted: Tue Mar 24, 2009 11:50 am
by ninethousandfeet
i tried using DISTINCT and it had no affect on my results... can you think of any other way to do it?

Re: SQL to get Unique Email

Posted: Wed Mar 25, 2009 12:07 am
by sujithtomy
Hello,

I am not sure this way is correct, but unless you find a good answer you can try as follows,

get all email-ids to an array (php), use array_unique() —which Removes duplicate values from an array,
then pass result to mailing program.

Good Luck!! :)

Regards,
Sujith