title: How to combine a "Left Join" with an "Or" Mysql Statement?
body: <p>I have a very complicated task, I need to pull from 3 different tables and compare with several conditions.</p>
  
  <p>These are the tables:</p>
  
  <p><strong>FOLLOW:</strong> - UserID, FollowID, Date</p>
  
  <p><strong>NOTIFICATIONS</strong> - ID, TypeID, Date, FromID, Link</p>
  
  <p><strong>NOTICONNECT</strong> - NID, UserID, Viewed</p>
  
  <p>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).</p>
  
  <p><strong>So the logic that I came up with is:</strong></p>
  
  <p><em>If Notifications.ID = NotiConnect.NID AND NotiConnect.UserID='MyID'</em></p>
  
  <p>OR</p>
  
  <p><em>Follow.FollowID = Notifications.FromID AND Follow.UserID = 'MyID' AND Notification.Date >= Follow.Date</em></p>
  
  <p>So can anyone show me how to write this up in mysql and php?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>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.</p>
  
  <p><strong>Conclusion</strong>: 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.</p>
  
  <p>Hope this helps for anyone else.</p>