请教一个简单的两个表关联查询的sql问题?多谢!!

[复制链接]
查看11 | 回复7 | 2007-1-24 14:35:02 | 显示全部楼层 |阅读模式
我要查询两个表中的记录
其中表一:
select id,caption from t_app where id=1
显示为三条记录

表二:
select id from t_u_app where uid=28
显示为两条记录(这两条是前面那三条的子集)
请问怎么查询这表一中比表二种多出的那一条呢?

我写了一个语句,不对啊
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
用外连接就可以了
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
不好意思,我可能没说明白
要求的结果是只返回这表一中多出的一条记录,而不返回其他的
求解!!
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
select id,caption
from t_app t1,t_u_app t2
where t1.id=t2.id(+)
and id=1
and uid=28;
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
楼上的,你这是查出那两条相同的,我是想查出那条不同的阿?
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
select id,caption from t_app where id=1
minus
select id ,caption from t_u_app where uid=28
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
select id,caption
from t_app t1 left join t_u_app t2
on t1.id=t2.id and uid=28
where id=1
and t2.id is null;
回复

使用道具 举报

千问 | 2007-1-24 14:35:02 | 显示全部楼层
外联或者not in,不过后者效率低下。
select id,caption
from t_app t1,t_u_app t2
where t1.id=t2.id(+)
and id=1
and uid=28 and t2.id is null;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行