好的,我有第一个表,其中包括:
表 1: id | depID
(每个id都有一个depID)
然后,我有第二个表,其中有表 2:userID | depID
(其中一个 userID 与单独行中的多个 depID 相关联。另外,我有 表 3 和 userID |rankID
(其中一个 userID 与一个排名ID)。
我需要从表1中获取所有id和depID,然后检查表2的哪些userID共享相同的depID(table1.depID = table2.depID),然后检查表中的哪些userID 2 的rankID = $rID
谢谢大家。
最佳答案
我认为这个 SQL 应该能让你得到你想要的,但从问题的措辞中我并不是 100% 清楚:
SELECT table2.userID
FROM table1
JOIN table2
ON table1.depID = table2.depID
JOIN table3
ON table2.userID = table3.userID
AND table3.rankID = $rID;
关于php - 一个复杂的mysql连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6070547/