|
-
Aug 24th, 2004, 11:44 AM
#1
Thread Starter
Lively Member
Selecting data based on 2 tables
What I am trying to do is to write a query that finds all records in Table ADS that do not have a corrisponding record in the tables PROOFS. Help
SELECT *
FROM Ads
WHERE AdNums NOT IN
(SELECT Proofs.AdNums
FROM proofs))
Ads
AD_ID Long
RevisionDate Date
AdNums long
Proofs
Ad_ID
.....
AdNums long
Ads
-
Aug 25th, 2004, 12:15 AM
#2
Hyperactive Member
Your query should be working. What problems are you having?
-
Aug 25th, 2004, 12:21 AM
#3
Try this...
Code:
SELECT *
FROM Ads
WHERE Ads.AdNums NOT EXISTS
(SELECT Proofs.AdNums
FROM proofs))
From SQL BOL:
When a subquery is introduced with the keyword EXISTS, it
functions as an existence test. The WHERE clause of the outer
query tests for the existence of rows returned by the subquery.
The subquery does not actually produce any data; it returns a
value of TRUE or FALSE.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 27th, 2004, 01:05 AM
#4
Hyperactive Member
Originally posted by RobDog888
Try this...
Code:
SELECT *
FROM Ads
WHERE Ads.AdNums NOT EXISTS
(SELECT Proofs.AdNums
FROM proofs))
This will not work. What slr have should be working, if we want to try your code, we should do this:
Code:
SELECT *
FROM Ads
WHERE NOT EXISTS
(SELECT Proofs.AdNums
FROM proofs WHERE Ads.AdNums = Proofs.AdNums)
Also, I suggest that you name your columns differently next time. Say Ads.AdNums, Proofs.RefAdNums.
Also (again), this might just be typo error but check your code again:
Originally posted by slr
What I am trying to do is to write a query that finds all records in Table ADS that do not have a corrisponding record in the tables PROOFS. Help
SELECT *
FROM Ads
WHERE AdNums NOT IN
(SELECT Proofs.AdNums
FROM proofs))
Ads
AD_ID Long
RevisionDate Date
AdNums long
Proofs
Ad_ID
.....
AdNums long
Ads
you have unmatched parenthesis, again, it might just be typo error (here in the forum), but it won't work in your query.
-
Aug 27th, 2004, 04:06 AM
#5
SELECT *
FROM Ads
WHERE AdNums NOT IN
(SELECT Proofs.AdNums
FROM proofs))
Code:
Select * from Ads left join AdNums on ads.[idfield]=adnums.[idfield] where adnums.[idfield] is null
id field in ads and in adnums are the two related fields.
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|