A complicated mysql join
Ok, I have this first table which has, among other things:
table 1: id | depID
(every id has one depID)
Then, I have a second table where I have table 2: userID | depID
(where an开发者_JS百科 userID is associated with multiple depIDs in separate rows. Also, I have table 3 with userID | rankID
(where an userID is associated with one rankID).
I need to get all id and depID from table 1, and then to check, which userIDs of table 2 shares the same depID (table1.depID = table2.depID), and then, to check which of those userIDs from table 2 has rankID = $rID
Thanks guys.
I think this SQL should get you what you want, but I'm not 100% clear from the wording of the question:
SELECT table2.userID
FROM table1
JOIN table2
ON table1.depID = table2.depID
JOIN table3
ON table2.userID = table3.userID
AND table3.rankID = $rID;
精彩评论