27,579
社区成员
发帖
与我相关
我的任务
分享
select b.* from a join b on a.id2=b.id where a.id1=1
select b.* from a,b where a.id2=b.id and a.id1=1
if object_id('a') is not null
drop table a
go
create table a([id1] varchar(10),[id2] varchar(10))
insert a select 1,'2'
insert a select 1,'3'
insert a select 2,'2'
insert a select 2,'3'
insert a select 2,'4'
go
if object_id('b') is not null
drop table b
go
create table b([id] varchar(10),[img] varchar(10))
insert b select '1','1.jpg'
insert b select '2','2.jpg'
insert b select '3','3.jpg'
go
select b.* from a join b on a.id2=b.id and a.id1=1
/*
id img
---------- ----------
2 2.jpg
3 3.jpg
(2 行受影响)
*/
select b.* from a join b on a.id2=b.id and a.id=1