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, separated with commas?
What I have currently is just and u and d tables corresponding to each other.
SELECT
e.userid,
e.divid,
d.divname
FROM
e
LEFT JOIN d ON (e.divid = d.id)
ORDER BY e.userid