470,614 Members | 1,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

HOWTO: Join 3 Tables, Compare Unequals To 1 Table

I have a tough SQL join query and I figured it out, so I thought you
might find it useful.

I have 3 tables with tracking numbers in them. I want to think of the
sum of all these tracking numbers, then find non-matches to a master
tracking number table. When I find non-matches (orphans) in the master
tracking number table, I want to eliminate the orphans.

The master table is "master_tn". The column in question is "tn"
(tracking number).

((select tn from master_tn except select tn from opentickets) except
select tn from voidedtickets) except select tn from resolvedtickets

There you go. Enjoy!

If anyone can optimize that even better, I would welcome it.
Jul 19 '05 #1
1 5263
go********@hotpop.com (Google Mike) wrote in message
I have a tough SQL join query and I figured it out, so I thought you
might find it useful.

I have 3 tables with tracking numbers in them. I want to think of the
sum of all these tracking numbers, then find non-matches to a master
tracking number table. When I find non-matches (orphans) in the master
tracking number table, I want to eliminate the orphans.

The master table is "master_tn". The column in question is "tn"
(tracking number).

((select tn from master_tn except select tn from opentickets) except
select tn from voidedtickets) except select tn from resolvedtickets

There you go. Enjoy!

If anyone can optimize that even better, I would welcome it.


Of course, that merely shows you how to select the data. To delete it,
you have to do:

delete from master_tn where tn in (((select tn from master_tn except
select tn from opentickets) except select tn from voidedtickets)
except select tn from resolvedtickets)
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by HS Hartkamp | last post: by
6 posts views Thread by Ian Boyd | last post: by
1 post views Thread by Dot Net Daddy | last post: by
2 posts views Thread by JP2006 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.