--使用Northwind --连接查询 --内连接(Inner Join) select p.* from Products p inner join [Order Details] o on p.ProductID=o.ProductID go select p.*,c.* from Products p inner join Categories c on c.CategoryID=p.CategoryID go --1、左外连接 select p.*,c.* from Categories c left outer join Products p on p.CategoryID=c.CategoryID order by p.ProductID --2、右外连接 select p.*,c.* from Categories c right outer join Products p on p.CategoryID=c.CategoryID order by p.ProductID --3、全外连接 select p.*,c.* from Categories c full outer join Products p on p.CategoryID=c.CategoryID order by p.ProductID --子查询 --1、使用比较运算符的子查询 select * from Products where unitprice>(select avg(unitprice) from Products) --2、使用IN的子查询 select * from Products where categoryID in (select categoryID from categories) --3、使用some和any的子查询 select * from Products where unitprice<some(select avg(unitprice) from Products) --4、使用All的子查询 select * from Products where unitprice<>All(select avg(unitprice) from Products) --5、使用Exists的子查询 select * from Products where exists (select * from categories where categories.categoryID=Products.categoryID and categories.categoryID=2)
相关文章:
- SQL--联合查询【Union】 2021-12-08
- SQL-联合查询union 2022-03-13
- SQL-关联查询 SQL-关联查询 2021-11-30
- MySQL的查询,子查询,联结查询,联合查询 2022-12-23
- 子查询 & 联合查询 2021-12-09
- 连接查询,子查询,联合查询 2021-07-10
- 连接查询、子查询、联合查询 2022-12-23