PHP SQL, SELECT corresponding data from 3 tables at once?

Posted by user346325 on Stack Overflow See other posts from Stack Overflow or by user346325
Published on 2010-05-20T17:06:00Z Indexed on 2010/05/20 17:10 UTC
Read the original article Hit count: 103

Filed under:
|
|

I have 3 tables, 'u' 'd' 's'

'u' has

  • userid
  • divid

'd' has

  • divid
  • divname

's' has

  • sname
  • primaryuserid
  • secondaryuserid

Now what I'd like to do is display a table with rows of the following format

  • userid, divname, sname

Plus figure out a way to decipher whether userid is a primary or secondary for this sname table.

I'm able to show userid and divname using a left join, but I don't know how I would add a third table? To make it trickier, there can be more than 1 snames for each userid, up to ~20. Is there a way to display 0-20 snames depending on the userid, seperated with commas?

© Stack Overflow or respective owner

Related posts about php

Related posts about sql