免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2909 | 回复: 6
打印 上一主题 下一主题

请教:左连接在11.9.2以下版本中的使用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-18 20:41 |只看该作者 |倒序浏览
select a.field1,a.field2
from a,b
left join on a.field1=b.field1
where a.feld2 is null
用*=怎么才能实现相同的效果?
试了几次,换成*=之后a.feld2 is null就起不到过滤作用了.

论坛徽章:
0
2 [报告]
发表于 2006-04-18 22:17 |只看该作者
create table dept(dept_id int, dept_name varchar(20) null)
go
insert into dept values(1,'Tech Support')
go
insert into dept values(2,'HR')
go
create table emp(dept_id int,emp_id int, name varchar(20) null)
go
insert into emp values(1,1,'Bush')
go
insert into emp values(1,2,'JingTao')
go
insert into emp values(2,1,'Qingshihuang')
go
insert into emp values(2,2,'MaoZeDong')
go
insert into emp values(3,1,'foo')
go
insert into emp values(3,2,null)
go

select emp.dept_id,emp.emp_id,emp.name
from emp,dept
where emp.dept_id *= dept.dept_id
go

select emp.dept_id,emp.emp_id,emp.name
from emp,dept
where emp.dept_id *= dept.dept_id and emp.name is null
go

dept_id emp_id name
          3          2  NULL

论坛徽章:
0
3 [报告]
发表于 2006-04-18 22:18 |只看该作者
tested in 11.0.3

论坛徽章:
0
4 [报告]
发表于 2006-04-19 17:23 |只看该作者
不好意思,是我没说清楚.
现在的情况是:
如果有一条不满足关联条件的记录,dept表的字段自动补NULL,
我的目的是想把这一条取出来.

论坛徽章:
0
5 [报告]
发表于 2006-04-19 22:36 |只看该作者
create table dept(dept_id int, dept_name varchar(20) null)
go
insert into dept values(1,'Tech Support')
go
insert into dept values(2,'HR')
go
create table emp(dept_id int,emp_id int, name varchar(20) null)
go
insert into emp values(1,1,'Bush')
go
insert into emp values(1,2,'JingTao')
go
insert into emp values(2,1,'Qingshihuang')
go
insert into emp values(2,2,'MaoZeDong')
go
insert into emp values(3,1,'foo')
go

select emp.dept_id,emp.emp_id,dept.dept_name
from emp,dept
where emp.dept_id *= dept.dept_id
and dept.dept_name is null
go

dept_id     emp_id      dept_name            
----------- ----------- ---------            
          1           1 NULL                 
          1           2 NULL                 
          2           1 NULL                 
          2           2 NULL                 
          3           1 NULL

论坛徽章:
0
6 [报告]
发表于 2006-04-19 22:36 |只看该作者
create table dept(dept_id int, dept_name varchar(20) null)
go
insert into dept values(1,'Tech Support')
go
insert into dept values(2,'HR')
go
create table emp(dept_id int,emp_id int, name varchar(20) null)
go
insert into emp values(1,1,'Bush')
go
insert into emp values(1,2,'JingTao')
go
insert into emp values(2,1,'Qingshihuang')
go
insert into emp values(2,2,'MaoZeDong')
go
insert into emp values(3,1,'foo')
go

select emp.dept_id,emp.emp_id,dept.dept_name
from emp,dept
where emp.dept_id *= dept.dept_id
and dept.dept_name is null
go

dept_id     emp_id      dept_name            
----------- ----------- ---------            
          1           1 NULL                 
          1           2 NULL                 
          2           1 NULL                 
          2           2 NULL                 
          3           1 NULL

论坛徽章:
0
7 [报告]
发表于 2006-04-19 22:41 |只看该作者
我的目的只是最后一条,据说在11.9.2以上版本用left join就能实现,
但条件不允许升级数据库,用游标也能实现,不过如果有简单方法更好.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP