Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Name the cities that had no one purchasing...

Author  Topic 

adamantium007
Starting Member

4 Posts

Posted - 2011-03-19 : 13:39:34
Name the cities that had no one purchasing any books in English?

Select distinct cust.city From YRB_customer cust, YRB_purchase p, YRB_book b Where cust.cid =p.cid and p.title=b.title and b.language = 'English'

I have gotten the query so far to only give those cities that have books in English, but I want to show that "no one has purchase any books in English"

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-03-19 : 13:56:08
Do you mean this?
Select distinct cust.city 
From YRB_customer cust
left join YRB_purchase p on cust.cid =p.cid
left join YRB_book b on p.title=b.title and b.language = 'English'
Where b.title is null



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

adamantium007
Starting Member

4 Posts

Posted - 2011-03-19 : 14:08:01
It still shows all the cities where people bought the book in english.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-03-19 : 14:22:47
You must be wrong.
See this:
create table YRB_customer(cid int identity(1,1),city varchar(255))
create table YRB_purchase(pid int identity(1,1),cid int,title varchar(255))
create table YRB_book(bid int identity(1,1),title varchar(255),language varchar(255))

insert YRB_customer (city)
select 'Hamburg' union all
select 'London' union all
select 'New York'

insert YRB_purchase (cid,title)
select 1,'a title' union all
select 2,'another title'

insert YRB_book (title,language)
select 'a title','German' union all
select 'another title','English'

Select distinct cust.city
From YRB_customer cust
left join YRB_purchase p on cust.cid =p.cid
left join YRB_book b on p.title=b.title and b.language = 'English'
Where b.title is null

drop table YRB_customer
drop table YRB_purchase
drop table YRB_book



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

adamantium007
Starting Member

4 Posts

Posted - 2011-03-19 : 14:51:38
here is the link to the source code

however if there is more than one language for all books available then it will still show all the cities where the cities had no one buying the book in English (ie/ japanese, german...)

your query still list me all the cities.

i am a beginner so i am still lost having to do this assignment that is beyond my level for an intro course.

Go to Top of Page
   

- Advertisement -