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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing two sub_queries 1

Status
Not open for further replies.

tk94kato

MIS
Oct 22, 2005
5
US
I need to return the rows that are NOT duplicated. I am trying to be sure information on one db is the same on another db. I just need the odd rows returned. Is there an opposite of the union function?

EX> Query 1 returns

acct_num product_id count
1507692 100000500 1
1846486 106 3
1846486 100000500 1

Query 2 returns the same.

I want the row returned if they aren't the same.

 
How about:
[tt]
SELECT 1,tbl1.*
FROM tbl1 LEFT JOIN tbl2
USING (acct_num,product_id,count)
WHERE tbl2.acct_num IS NULL
UNION
SELECT 2,tbl2.*
FROM tbl1 RIGHT JOIN tbl2
USING (acct_num,product_id,count)
WHERE tbl1.acct_num IS NULL
[/tt]
This will return the tbl1 rows which do not exist in tbl2, and the tbl2 rows which do not exist in tbl1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top