首页 > php教程 > php手册 > 级联查询 EXISTS与 IN互换

级联查询 EXISTS与 IN互换

WBOY
发布: 2016-06-06 20:01:09
原创
1122 人浏览过

--联接 SELECT FROM dbo.k_baoming INNER JOIN dbo.k_kebiao ON dbo.k_baoming.o_flowid = dbo.k_kebiao.f_apply_id --左向外联接 SELECT dbo.k_baoming.o_flowid FROM dbo.k_baoming LEFT OUTER JOIN dbo.k_kebiao ON dbo.k_baoming.o_flowid = dbo.k_kebia

--联接
SELECT
FROM dbo.k_baoming INNER JOIN
      dbo.k_kebiao ON dbo.k_baoming.o_flowid = dbo.k_kebiao.f_apply_id


--左向外联接
SELECT dbo.k_baoming.o_flowid
FROM dbo.k_baoming LEFT OUTER JOIN
      dbo.k_kebiao ON dbo.k_baoming.o_flowid = dbo.k_kebiao.f_kebiaoID

--右向外联接
SELECT dbo.k_baoming.o_flowid
FROM dbo.k_baoming RIGHT OUTER JOIN
      dbo.k_kebiao ON dbo.k_baoming.o_flowid = dbo.k_kebiao.f_kebiaoID

--完整外部联接
SELECT dbo.k_baoming.o_flowid
FROM dbo.k_baoming FULL OUTER JOIN
      dbo.k_kebiao ON dbo.k_baoming.o_flowid = dbo.k_kebiao.f_kebiaoID


--可以不要OUTER

 

--EXISTS 与 IN 互换
SELECT * FROM Article WHERE classid in(SELECT ID FROM class WHERE parentID='219')
go
SELECT * FROM Article WHERE exists(SELECT ID FROM class WHERE class.id=Article.classid AND class.parentID='219')

 

IN适合于外表大而内表小的情况;EXISTS适合于外表小而内表大的情况。

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板