热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> 数据库>>正文内容

sql查询:联合查询

发布时间:2011年04月26日点击数: 佚名
  1. --使用Northwind 
  2. --连接查询 
  3. --内连接(Inner Join) 
  4. select  p.* from  Products p inner join [Order Details] o on p.ProductID=o.ProductID 
  5. go 
  6. select  p.*,c.* from  Products p inner join Categories c on c.CategoryID=p.CategoryID 
  7. go 
  8.   
  9. --1、左外连接 
  10. select  p.*,c.* from Categories c  left outer join Products p on p.CategoryID=c.CategoryID  order by p.ProductID 
  11. --2、右外连接 
  12. select  p.*,c.* from Categories c  right outer join Products p on p.CategoryID=c.CategoryID  order by p.ProductID 
  13. --3、全外连接 
  14. select  p.*,c.* from Categories c  full outer join Products p on p.CategoryID=c.CategoryID  order by p.ProductID 
  15. --子查询 
  16.   
  17. --1、使用比较运算符的子查询 
  18. select * from Products  where unitprice>(select avg(unitprice) from Products) 
  19. --2、使用IN的子查询 
  20. select * from Products where categoryID in (select categoryID from categories) 
  21. --3、使用some和any的子查询 
  22.   
  23. select * from Products  where unitprice<some(select avg(unitprice) from Products) 
  24.   
  25.   
  26.   
  27. --4、使用All的子查询 
  28. select * from Products  where unitprice<>All(select avg(unitprice) from Products) 
  29.   
  30. --5、使用Exists的子查询 
  31. select * from Products where  exists (select * from categories where categories.categoryID=Products.categoryID and categories.categoryID=2) 

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作