Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have found your site brilliant. What makes it good are the people that contribute to the site..."

Geography

Where in the world do Tek-Tips members come from?
exRP12Nuke (TechnicalUser)
19 Jun 12 10:22
Good Morning,

I have two tables, table 1 and table 2. The records that are in table 1 are extensive and are the records that I need to use further in my database. The records in table 2 are the records that I want to exclude from table 1. I would be joining the two tables on the WorkOrder fields. What kind of query to I need to build to accomplish this?

Thanks!
Andrzejek (Programmer)
19 Jun 12 11:09

Do those table have any uqnique key that you can use?
If so, I usually start getting the records that I want to exclude:

Select SomeID From Table2
Where ...


Then I just get the records I want using:

Select * from Table 1
Where SomeID NOT IN(
Select SomeID From Table2
Where ...
)

Have fun.

---- Andy

exRP12Nuke (TechnicalUser)
19 Jun 12 11:25
Andrzejek,

Thank you for your response, unfortunatly my SQL is rather weak so a little more assistance would be greatly appreciated. The two tables that I am working with are tblHist and qryWarrWO. The records in tblHist is the complete list of records that I am working with, while the records in qryWarrWO are the records that I am trying to exclude. There are three unique records that I would need to "join" and they are WONO, CompCode, and CPTMD3.

Thanks again!
exRP12Nuke (TechnicalUser)
19 Jun 12 11:50
This is the SQL that I came up with, but it does not return any results.

CODE

SELECT tblHist.WONO, tblHist.CompCode, tblHist.CPTMD3, *
FROM tblHist
WHERE (((tblHist.WONO) Not In (Select WONO from qryWarrWo)) AND ((tblHist.CompCode) Not In (Select CompCode from qryWarrWO)) AND ((tblHist.CPTMD3) Not In (select CPTMD3 from qryWarrWO)));

Thanks
Andrzejek (Programmer)
19 Jun 12 12:47

Let's take it one step at the time.
When you do:

Select WONO from qryWarrWo

How many records do you get?

When you do:

SELECT *
FROM tblHist

How many records do you get?

When you do:

SELECT *
FROM tblHist
WHERE WONO Not In
(Select WONO from qryWarrWo)

How many records do you get?

Have fun.

---- Andy

exRP12Nuke (TechnicalUser)
19 Jun 12 12:58
Andrzejek,

For Select WONO From qryWarrWO, it returns 79 records.

For Select * From tblHist, it returns 5897 records.

For Select * From tblHist Where Not In (Select WONO from qryWarrWO), it returns 5689 records.

There can be multiple CompCode and CPMTD3 for each WONO which is why the last SQL statement removes more than 79 records. For instance: Lets say that under WONO GT50000 they did an engine swap along with a left front wheel (I work for a heavy equipment dealer). So under WONO GT50000 there are CompCodes 1000 and 4006 with CPMTD3 LF. If WONO GT50000 shows up in qryWarrWO with CompCode 4006 and CPMTD3 LF I want that record to not show up, but leave the GT50000 CompCode 1000 in the final query.

Hope that explanation helps.

Thanks!
Andrzejek (Programmer)
19 Jun 12 13:36

OK, you may get better handle of this stuff if you do:

Select DISTINCT WONO From qryWarrWO
Select DISTINCT * From tblHist
Select DISTINCT * From tblHist Where Not In (Select DISTINCT WONO from qryWarrWO)

the numbers, math, should be easier.

Have fun.

---- Andy

PHV (MIS)
19 Jun 12 13:45
exRP12Nuke (TechnicalUser)
19 Jun 12 16:15
Thanks guys, the unmatched query with a few tweeks works great!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close