Write SQL Query Code Problem
am 09.01.2008 18:29:34 von 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
Re: Write SQL Query Code Problem
am 09.01.2008 19:10:39 von reb01501
Brett_A wrote:
> 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)
--
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.
Re: Write SQL Query Code Problem
am 09.01.2008 19:36:18 von Brett_A
On Jan 9, 1:10 pm, "Bob Barrows [MVP]"
wrote:
> Brett_A wrote:
> > 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)
>
> --
> 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