一、子查询
由于我们在where 后跟的条件是确定的,但如果我们还不知道我们判断的条件或是我们判断的条件需要通过另外的查询去查找时,我们可以在where之中嵌套一个查询语句完善该次查询
1.1 嵌套查询
select user.name,product.name from product join user where product.id in( select ordered.name from ordered where id in (select user.ordered from user where user.id = 1) );
原始表
结果
1.2 子查询
select user.name,product.name from user join ordered on user.ordered = ordered.name join product on ordered.id = product.id where user.id = 1;
结果