I have problem in sql query

Posted by Nuwan under Sql Server on 11/6/2012 | Points: 10 | Views : 796 | Status : [Member] | Replies : 2
I have two table like t1 and t2, it have same no,
I want to get a not equal number in t1 to t2
Like t1.no <> t2.no

Please help me.

Rathnayake


Responses

Posted by: Pandians on: 11/6/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Try with FULL OUTER JOIN
Select A.No [T1],B.No [T2] from T1 A Full Outer Join T2 B On (A.No = B.No)

Go
So, you'll get both mismatch from T1 and T2

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 11/7/2012 [Member] Starter | Points: 25

Up
0
Down
hi..

please try the following query.......

provided both tables should have similar datatypes to compare...

(

Select * from Table_1
Except
Select * from Table_2
)
Union
(
Select * from Table_2
Except
Select * from Table_1
)


Example:

Declare @temp1 table

(
id int,
name varchar(10)
)

Insert into @temp1 values(1,'A')
Insert into @temp1 values(2,'B')
Insert into @temp1 values(3,'C')

Declare @temp2 table
(
id int,
name varchar(10)
)

Insert into @temp2 values(1,'A')
Insert into @temp2 values(2,'B')
Insert into @temp2 values(4,'D')


(
Select * from @temp1
Except
Select * from @temp2
)
Union(

Select * from @temp2
Except
Select * from @temp1
)


Sourabh07

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response