废话不多说 直接上code:
--创建测试表结构:
create table test_left_a (
a varchar2(50),
b varchar2(50)
)
create table test_left_b (
a varchar2(50),
b varchar2(50)
)
--插入测试数据:
insert into test_left_a select 'a','21' from dual;
commit;
insert into test_left_a select 'c','2111' from dual;
commit;
insert into test_left_b select 'a','12' from dual;
commit;
insert into test_left_b select 'b','13' from dual;
commit;
--实现左连接查询(不加where)的几种语法:
A:
select * from test_left_a a left join test_left_b b on a.a = b.a;
B:
select * from test_left_a a, test_left_b b where a.a = b.a(+);
C:
select *
from test_left_a a
inner join test_left_b b on a.a = b.a(+);
--实现左连接查询(加where)的几种语法:
D:
select *
from test_left_a a
left join test_left_b b on a.a = b.a
where a.a = b.a;
E:
select *
from test_left_a a, test_left_b b
where a.a = b.a(+)
and a.a = b.a;
F:
select *
from test_left_a a
inner join test_left_b b on a.a = b.a(+)
and a.a = b.a;
G:
select *
from test_left_a a
inner join test_left_b b on a.a = b.a(+)
where a.a = b.a;
测试结论:
以上几种查询(暂不考虑性能,只考虑用法)
A等价于B等价于C
查询结果:
a 21 a 12
c 2111
D等价于E等价于F等价于G
查询结果:
a 21 a 12
注意:
1.使用inner join的时候 直接在on后面写条件和增加where后再写条件是一样的,原因是内连接是匹配出on条件为真的记录(参考F和G)
2.使用left join或者right join的时候,直接在on后面写条件和增加where后再写条件是不一样的,原因是
left join即使on后面的条件为假也会显示出左表的所有记录
right join即使on后面的条件为假也会显示出右表的所有记录
(这也是D语句中需要用where的原因)
继续阅读与本文标签相同的文章
谷歌的“Duplex”系统在与人交谈时能识别自己
mysql删除重复数据保留最大或最小的一条
-
斩获三个“全国第一”,漳州有一家“隐形冠军”企业
2026-05-18栏目: 教程
-
经历8个月改造,岗顶百脑汇“转型回归”
2026-05-18栏目: 教程
-
ROKU流媒体聚合平台终将变革电视机操作系统和流媒体的观看方式
2026-05-18栏目: 教程
-
权威报告:中国专利申请连续8年居首,占世界一半
2026-05-18栏目: 教程
-
新技术:AI可快速准确检测因糖尿病造成的视网膜病变
2026-05-18栏目: 教程
