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

Querying values that are in one table but not the other 1

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
Hi,

its been awhile since I used Access jet engine. I'm having a problem with the following query. I set it up how I normally do using other databases, but it returns zero results when I try to run it in access.

I want to get the values from the temp table that do not exist in the site table. Not sure what I'm doing wrong:
Code:
         strSQL = "SELECT "
         strSQL = strSQL & "DISTINCT tmp.Rec_ID, tmp.[Site ID]"
         strSQL = strSQL & " FROM tmpExcelUpload tmp WHERE tmp.[Site ID] NOT IN(SELECT [tblSite-type].[Site ID] FROM [tblSite-type])"
 
That seems ok, it works for me. Could the field types be different?
 
both the fields are text fields. Thought I would try
adding single quotes around the not in statement but that returns all records instead of none. Not sure why this isn't working.
 
Have you tried pasting the SQL into the query design screen?
 
Yes, with no luck. I got the following to work as a query, but i can only get it to select one field instead of two (works with site id, but when I try to select rec_id as well it errors out)

Code:
SELECT tmpExcelUpload.[Site ID]
FROM [SELECT tmpExcelUpload.[Site ID], [tblSite-Type].[Site ID] FROM tmpExcelUpload LEFT JOIN [tblSite-Type] ON tmpExcelUpload.[Site ID] = [tblSite-Type].[Site ID]]. AS [%$##@_Alias]
WHERE ISNull([tblSite-Type].[Site ID]);
 
Try:

SELECT tmpExcelUpload.Rec_ID,tmpExcelUpload.[Site ID]
FROM tmpExcelUpload LEFT JOIN [tblSite-Type] ON tmpExcelUpload.[Site ID] = [tblSite-Type].[Site ID]
WHERE [tblSite-Type].[Site ID] Is Null
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top