If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Help. sql query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-30-03, 14:34
fandangos fandangos is offline
Registered User
 
Join Date: Sep 2003
Posts: 3
Help. sql query

i need an sql statement to list all the papers and whether or not Jacque chirac is subscribed to them. It must be outputted in the following way, and not in a view.

Paper Subscribed
Daily mail True
Guardian True
Metro False
Sun True
Times False

with data coming from the following tables

PAPER
paperid Papername Price
1 Guardian 45
2 Times 45
3 Sun 25
4 Metro 0
5 Daily mail 35

PERSON
personid firstname lastname
1 Jacque Chirac
2 George Bush

SUBSCRIBED
personid paperid
1 1
1 3
1 5
2 3
2 4


Thanks in advance guys
Reply With Quote
  #2 (permalink)  
Old 09-30-03, 18:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
sounds like homework

what have you managed to come up with on your own so far?

rudy
Reply With Quote
  #3 (permalink)  
Old 10-01-03, 05:46
fandangos fandangos is offline
Registered User
 
Join Date: Sep 2003
Posts: 3
LOL Homework. I have just come out of university and i am trying to extend my sql skills. I am unsure about the boolean part of this query and how to make the column with true/false in it. So far i can find out which papers Jacque is subscribed to using the following query


select paper.papername
from paper, person, subscription
where paper.paperid = subscription.paperid and subscription.personid = person.personid and person.firstname='Jacque' and person.lastname = 'Chirac';



help please! i am really stuck
Reply With Quote
  #4 (permalink)  
Old 10-01-03, 07:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
okay, change what you have as follows --

select paper.papername
, case when person.firstname='Jacque'
and person.lastname = 'Chirac'
then 'True' else 'False' end
from paper, person, subscription
where paper.paperid = subscription.paperid
and subscription.personid = person.personid

rudy
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-01-03, 07:26
fandangos fandangos is offline
Registered User
 
Join Date: Sep 2003
Posts: 3
Thumbs up

Thanks mate. i really appreciate that
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On