Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SELECT staffNO, name, surname, position FROM Staff s, Branch b WHERE s.branchNo = b.branchNo AND city = 'London';
我试图将上面的 SQL 代码变成一个子查询,但我没有得到任何结果。我是SQL初学者,我该怎么做?
具有子查询和IN子句的等效查询如下所示:
IN
SELECT staffNO, name, surname, position FROM Staff s WHERE s.branchNo IN ( SELECT b.branchNo FROM Branch b WHERE b.city = 'London' );
这当然假设staffNO, name, surname, position所有这些都可以作为Staff表格上的字段使用。如果这些字段中的任何一个来自,Branch那么您确实需要使用该JOIN语法。
staffNO, name, surname, position
Staff
Branch
JOIN