sql server - SQL Query to produce email list based on specific requirements -
i can't seem figure out best way this. logic: think of facebook example. if comment on post, following post should email, not me initial comment. should receive notification when others comment on post i'm following.
posta: i'm following
postb: i'm following
posta: posted comment
postb: else posted comment
i should email postb not posta.
next...
postb: posted comment.
i should not notification other person should.
i'm using personalized email scheduler , here work-flow:
- i set run condition.
- i set recipients list using sql query.
- i create personalized inserts email (i.e. new comments on post you're following).
i have 3 tables example:
- postfollowers (userid, email, postid)
- post (postid, message, notification_sent <- bit)
- postcomments (commentid, userid, comment, notification_sent <- bit)
step1: set run condition
select * postcomments notification_sent = 0
if values returned application execute campaign.
step2: select recipients
select a.email ,a.postid postfollowers inner join postcomments b on a.postid = b.postid b.notification_sent = 0
so above recipients query includes person following post have comments haven't been sent notifications yet.
what best way adjust query recipients following post, related comment not own. should email if comments exist not created themselves. time goes , i've posted 10 comments on 1 post. email should go out other person following. comes along , posts comment. should email.
i'm over-thinking this. perhaps count subtracts comments , in clause?
thank , i'm bit tired... hope question clear.
as nogotnu has mentioned below query should work
select pf.email ,pf.postid postfollowers pf inner join postcomments pc on pf.postid = pc.postid pc.notification_sent = 0 , pf.userid != pc.userid
Comments
Post a Comment