Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Comments
Raja Sekhar S 20-Sep-13 6:51am    
Is this Your Question...
Select People present in first table and not in second table..?
Customer and Calls are different tables... or it is a single table..?
mahesh202 20-Sep-13 6:59am    
2 diff tables

1 solution

SQL
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 
 
Share this answer
 
Comments
Raja Sekhar S 20-Sep-13 8:02am    
u got what you are looking for..?
mahesh202 20-Sep-13 8:42am    
than q
Raja Sekhar S 20-Sep-13 8:47am    
if it solved your problem mark it as answer...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900