• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Complex join statement

I'm programming a private message system for users. The table pmessages stores userID's in the field mRecipient and mAuthor. When I access a message I want to join both those fields to the field userID in the table users so i can display usernames instead of userID's

Is there syntax to do this in one query or do i need to do two...?

basically i want to join two seperate fields in one table to the same field in another table


I think you have to join the user table twice, one time for the recipient and one time for the author.

Something like this (approximate syntaxe) :

FROM messages m
JOIN users u1 having (u1.userid = m.authorid)
JOIN users u2 having (u2.userid = m.recipientid)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.