开发者

How to combine a "Left Join" with an "Or" Mysql Statement?

I have a very complicated task, I need to pull from 3 different tables and compare with several conditions.

These are the tables:

FOLLOW: - UserID, FollowID, Date

NOTI开发者_如何学JAVAFICATIONS - ID, TypeID, Date, FromID, Link

NOTICONNECT - NID, UserID, Viewed

Let me explain the situation, this is for a notification system for a social network. First I want to pull generic notifications such as: receiving a message or comments. Second I also want to receive notifications of those users who I am following when they add an item (kind of like how twitter has follow and let you know when they tweet).

So the logic that I came up with is:

If Notifications.ID = NotiConnect.NID AND NotiConnect.UserID='MyID'

OR

Follow.FollowID = Notifications.FromID AND Follow.UserID = 'MyID' AND Notification.Date >= Follow.Date

So can anyone show me how to write this up in mysql and php?

Thanks!

UPDATE

It turns out I was going about this all wrong. I wanted to determine if a user was following another user and whether it was past the "start following date". This was to prevent any notifications prior to "start following date" to show up because the user was not following before then.

Conclusion: When adding a notification row to the table, add a notiConnect to those who are following the user. This eliminates any possible notification prior to the follow.

Hope this helps for anyone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜