如何合并两个选择和两个where子句?

时间:2019-07-02 20:42:30

标签: mysql sql

表一:

StudentId,  StudentName,  School
1           Sam            ABC

表二:

StudentCity  StudentId
Paris         1
mexico        2

答案应为“ Paris”,因为StudentId为1

select StudentCity 
from TWO
where StudentId = (select StudentId from ONE where StudentName="SAM"); 

请建议我进行SQL查询。

1 个答案:

答案 0 :(得分:2)

select StudentCity from TWO 
inner join ONE on ONE.StudentId = TWO.StudentId
where ONE.StudentName= "SAM"