Write SQL Query Code Problem

B

Brett_A

I have two tables, Advertisers and Ads. There is a one to many
relationship from Advertisers to Ads.

I want a listing of Advertisers that haven't placed any Ads.

I'm having a mental block on writing the SQL to pull that data.

Any ideas.

Thanks.

Brett
 
B

Bob Barrows [MVP]

Brett_A said:
I have two tables, Advertisers and Ads. There is a one to many
relationship from Advertisers to Ads.

I want a listing of Advertisers that haven't placed any Ads.

I'm having a mental block on writing the SQL to pull that data.
Think "left outer join ... where ad.keycolumn is null"

Alternatively think about "WHERE NOT EXISTS"

With no details about your table key columns and your database, I really
can't get too specific without inventing something like this:

select v.* from
Advertisers v left join Ads a on v.AdvertiserID = a.AdvertiserID
WHERE a.AdID is null

or

SELECT * FROM Advertisers v
WHERE NOT EXISTS (
select * from Ads a WHERE v.AdvertiserID = a.AdvertiserID)
 
B

Brett_A

Think "left outer join ... where ad.keycolumn is null"

Alternatively think about "WHERE NOT EXISTS"

With no details about your table key columns and your database, I really
can't get too specific without inventing something like this:

select v.* from
Advertisers v left join Ads a on v.AdvertiserID = a.AdvertiserID
WHERE a.AdID is null

or

SELECT * FROM Advertisers v
WHERE NOT EXISTS (
select * from Ads a WHERE v.AdvertiserID = a.AdvertiserID)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Got it Bob, thanks!

Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top