Jump to content

Recommended Posts

Hi,

 

I'm trying to set up a "Notify me when someone comments on a blog entry I have commented on" script, similar to what you get in facebook.

 

I have a comments table, where the username, comment, and blog entry number are entered whenever someone comments.  And a preferences table, which I have joined with the comments table.

 

The only problem is that when I pull all the usernames from the comments table of users who have commented on a particular blog entry, to send them a notification, a user who has commented ten times on a particular blog entry gets ten notifications.  You see the problem?

 

Is there any way of telling mysql (or by using php) to only send one notification per username? (LIMIT 1 won't work, obviously, as there may be more than one user who has commented on a particular blog entry.  I need something like a LIMIT DISTINCT usernames).

 

Any help much appreciated.

 

Julian

Link to comment
https://forums.phpfreaks.com/topic/196660-avoiding-duplicates/
Share on other sites

SELECT DISTINCT looks for distinct rows.  You need to select only the fields that you need AND are distinct:

 

SELECT DISTINCT userid, blogid FROM ...

 

or if you need other data, say how many comments the user has made on the blog, you can use GROUP BY:

 

SELECT userid, blogid, COUNT(commentid) FROM ... GROUP BY userid, blogid

 

which is distinct by virtue of the GROUP BY phrase

 

 

Link to comment
https://forums.phpfreaks.com/topic/196660-avoiding-duplicates/#findComment-1032519
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.