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

#1
[eluser]crumpet[/eluser]
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

#2
[eluser]tchule[/eluser]
Hello,

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) :

Code:
SELECT *
FROM messages m
JOIN users u1 having (u1.userid = m.authorid)
JOIN users u2 having (u2.userid = m.recipientid)

Tchule


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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