本文介绍了如何识别拥有第一名但没有第二名的人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表qstn是如何识别第一个没有第二个表的人只使用连接(不使用set或子查询的......)



客户来电

id nm id calid

1 xx 1 009

2 vv 5 999

i have 2 table qstn is how to identify the people who are having 1st one not having in 2nd table use only joins (not use set or subquery's...)

customer calls
id nm id calid
1 xx 1 009
2 vv 5 999

推荐答案

Create Table #Temp1 
	(
	 Id Int,
	 nm varchar(40)
	)

Create Table #Temp2
	(
	 Id Int,
	 CallId Int
	)

Insert into #Temp1
Values(1,'xx'),(2,'vv'),(3,'zz')

Insert into #Temp2
Values(1,09),(5,999)

Select t1.Id,t1.nm From #Temp1 t1	-- Present in #Temp1 not in #Temp2
Left Outer Join #Temp2 t2 on t1.Id=t2.Id
Where t2.Id is null

Select t2.Id,t2.CallId From #Temp1 t1	-- Present in #Temp2 not in #Temp1
Right Outer Join #Temp2 t2 on t1.Id=t2.Id
Where t1.Id is null

Select t1.Id,t1.nm,t2.CallId From #Temp1 t1	-- Present in Both Tables
Inner Join #Temp2 t2 on t1.Id=t2.Id

Select COALESCE(t1.Id,t2.Id)[Id],t1.nm,t2.CallId From #Temp1 t1	  -- Selecting All Records
Full Outer Join #Temp2 t2 on t1.Id=t2.Id

Drop Table #Temp1 
Drop Table #Temp2 


这篇关于如何识别拥有第一名但没有第二名的人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:56