什么是外连接?我糊涂了??!

[复制链接]
查看11 | 回复9 | 2007-1-6 21:14:12 | 显示全部楼层 |阅读模式
比如,在我的oracle9i里有两个表:
一个有一条记录 a
一个没有任何记录 b
...
from a left join b
where a.id=b.id
这样能不能得到一条返回的记录??我觉得可以!但好象我的数据库不行?不知道是什么原因!
请赐教!!谢谢!
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
能,这就外连接
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
相当于 from A,B where A.ID=B.ID(+)
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
here ia a detail explain
http://alvherre.atentus.cl/charlas/01-OuterJoin.pdf
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
各位老大!
SELECT * FROM player_info

LEFT JOIN player_match_info_hist ON player_match_info_hist.player_id =player_info.player_id
WHERE player_info.player_id = 1660
AND player_match_info_hist.game_kind = 1
AND substr(match_seq_no, 1, 4) = 2006
我的表是一张球员信息表和一张球员上场表现的表,
球员表中我查 player_info.player_id 为1660这个人的上场表现(2006赛季),但2006赛季还没有开始,所以没有记录在player_match_info_hist表里.(game_kind为1是指英超)
但我返回的记录总是0,郁闷中...
我用game_kind=2005连过,成功了,但是返回的类似全连接,没有任何left join该有的迹象!
实在是搞不懂了??!
我真想以为我现在是在做噩梦,希望早点醒来,55555
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
晕,打错了!!
我用substr(match_seq_no, 1, 4) =2005连过,成功了,但是返回的类似全连接,没有任何left join该有的迹象!
实在是搞不懂了??!
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
SELECT * FROM player_info
WHERE player_match_info_hist.player_id (+)=player_info.player_id
AND player_info.player_id = 1660
AND player_match_info_hist.game_kind = 1
AND substr(match_seq_no, 1, 4) = 2006
试试这样呢
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
解决了,谢谢各位!!
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
SELECT * FROM player_info
WHERE player_match_info_hist.player_id (+)=player_info.player_id AND substr(match_seq_no, 1, 4) = 2006

AND player_info.player_id = 1660
AND player_match_info_hist.game_kind = 1
回复

使用道具 举报

千问 | 2007-1-6 21:14:12 | 显示全部楼层
SELECT * FROM player_info
LEFT JOIN player_match_info_hist ON player_match_info_hist.player_id =player_info.player_id AND substr(match_seq_no, 1, 4) = 2006

WHERE player_info.player_id = 1660
AND player_match_info_hist.game_kind = 1
是这样解决的!
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行