Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare 3 Table in SQL

Status
Not open for further replies.

171171

Programmer
May 13, 2003
16
ID
hai
I have problem in syntax SQL .

Can you Help give the syntax ,
How can compare 3 tables with the record different ?
Example :
Table A and Table B and Table C

Table A is Record
NO. Name
001 Paper
002 Fish
003 Stick

Table B is Record
NO. Name
001 Paper
003 Stick

Table C is Record
NO. Name
001 Paper
003 Stick
004 Pen

Output
Table B diffrent with Table A is 002 Fish
Table C diffrent with Table A is 002 Fish
Table A diffrent with Table C is 004 Pen
Table B diffrent with Table C is 004 Pen


Can you give the syntax for me.


Thank You
 
select * from TableB where NO not in (select NO from TableA)

repeat for other tables. There's probably a dead clever way of doing this using UNION, but I can't think of it right now...

--------------------------------------------------
- better than toast.
Penguins - better than --------------------------------------------------
 
select 'Table B is different with Table A is '+a.no+' '+a.name from A full outer join B on A.no = B.no where B.no is null
--Output:Table B diffrent with Table A is 002 Fish


select 'Table C is different with Table A is '+a.no+' '+a.name from A full outer join C on A.no = C.no where c.no is null
--Output:Table C diffrent with Table A is 002 Fish


select 'Table A is different with Table C is '+c.no+' '+c.name from C full outer join A on C.no = A.no where A.no is null
--Output:Table A diffrent with Table C is 004 Pen


select 'Table B is different with Table C is '+c.no+' '+c.name from C full outer join B on C.no = B.no where B.no is null
--Output:Table B diffrent with Table C is 004 Pen

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top