Table1 Table2
ID Name ID Name
1 A 1 A
2 B 3 C
3 C
Get those records whose not having in table2 without using exist and not in
output:
ID Name
2 B
create table #table1
(
Id int Identity(1,1),
Name nvarchar(50)
)
create table #table2
(
Id int,
Name nvarchar(50)
)
ID Name ID Name
1 A 1 A
2 B 3 C
3 C
Get those records whose not having in table2 without using exist and not in
output:
ID Name
2 B
create table #table1
(
Id int Identity(1,1),
Name nvarchar(50)
)
create table #table2
(
Id int,
Name nvarchar(50)
)
insert into #table1(Name) values('A'),('B'),('C')
insert into #table2(Id,Name) values(1,'A'),(3,'C')
select ID,Name from #table1 EXCEPT select ID,Name from #table2
No comments:
Post a Comment