欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Left Jion和where区别

程序员文章站 2023-11-29 20:53:46
首先,新建两张表A和B,然后插入6条数据到A表,3条数据到B表。语句如下: 执行语句[select * from A left join B on A.ID=B.BID where B.BName=N'小明'],结果如下: 执行语句[select * from A left join B on A. ......

首先,新建两张表a和b,然后插入6条数据到a表,3条数据到b表。语句如下:

create table a(
    id int identity(1,1) not null,
    aname nvarchar(300) null
)
create table b(
    id int identity(1,1) not null,
    bid int  not null,
    bname nvarchar(300) null
)


insert into b(bname,bid) values(n'小明',2)
insert into b(bname,bid) values(n'小网',1)
insert into b(bname,bid) values(n'小刚',1)
insert into b(bname,bid) values(n'小蒋',1)
insert into b(bname,bid) values(n'小赵',1)
insert into b(bname,bid) values(n'小流',1)


insert into a(aname) values(n'一班')
insert into a(aname) values(n'二班')
insert into a(aname) values(n'三班')

执行语句[select * from a left join  b on a.id=b.bid where b.bname=n'小明'],结果如下:

Left Jion和where区别

执行语句[select * from a left join  b on a.id=b.bid and b.bname=n'小明'],结果如下:

Left Jion和where区别

 

写作时间:2017-11-8

=====================================================================================

本文只代表本人的见解,可能存在错误,仅用于技术交流。如果你喜欢该文,可以扫下面的二维码打赏我(打赏敬请备注“博客园打赏”五字)。

Left Jion和where区别