多表查询时,先把所有的表连接起来,再按要求查找,很方便

例如,现在有四张表:
supplier表(供应商表):
在这里插入图片描述
project表(工程表):
在这里插入图片描述
component表(零件表):
在这里插入图片描述
support表(供应信息表):
在这里插入图片描述
先把四张表连接起来:
select * from support,project,component,supplier where support.sno=supplier.sno and support.pno=component.pno and support.jno=project.jno;
在这里插入图片描述
比如,题目要求:查询为工程J1提供零件P3且数量在100个以上的所有供应商的供应商号、供应商名、提供零件数量。
根据上面的表很容易写出来查找的代码:

1
select support.sno,sname,qty from support,project,component,supplier where support.sno=supplier.sno and support.pno=component.pno and support.jno=project.jno and project.jno='J1' and component.pno ='P3' and qty > 100;