473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5339
go********@hotp op.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3055
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me solve my problem. I'll turn to MySQL doc after getting through this pressing project. Thanks a lot Roger! Babale -----Urspr=FCngliche...
3
8097
by: TH | last post by:
Hi, Trying to get a grip on the "join" thing :) Up until now, I allways used this kinda method: "(select t1.a from t1 where t1.b in (select t2.ab from t2 where t2.b=0))" How can this be accomplished using joins? And if you have the time please explain the "bits" :)
5
10857
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the new database. For instance, her old database has a table with Band Info in it. Her new database also has a table with Band Info in it but slightly...
2
3343
by: HS Hartkamp | last post by:
Hi all, I have a table with analysis-results for various months. An item can -for a particular month- have the result 'list1', 'list2' or 'list3' depending on the result of the analysis. Next, I want to get an insight in how the various items change over time. For that, I compare the results of one month with the results of another...
6
5909
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity seed, or your constraints, or your triggers, or your table. Talking to developers at other companies who have had the misfortune of using DB2, they...
1
1715
by: Dot Net Daddy | last post by:
Hi, I am new to MS-SQL and I have a problem. Actually I have made similar queries on Oracle, but now I failed on MS Sql. First of all I am using SQL Server 2005, but I think it is not that much important because my question is related something fundamental. I want to compare the result (which should be random) in one table, with another...
2
1321
by: JP2006 | last post by:
I have a situation where I have 2 tables - NODES and TAGS. Nodes is the main table and contains various columns one of which is tagID. Tags contains a list of tag names and tagIDs. When a user adds an entry to the Nodes table they can specify one or more tags for the entry. Then when the form is posted if there were multiple tags in the post...
5
24531
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate business days count which is defined as count of days (optionally inclusive in the current implementation) excluding weekend days and holidays. Let us...
2
1794
by: Idrisu | last post by:
Hello, i have this constellation on tables in my database: Table A id|content Table B table_a_id|table_c_id
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.