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 > SQL Assignment help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-11, 10:38
tsmith tsmith is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
SQL Assignment help

Hi
I have a question I need to answer for an assignment.
Here is the databse schema:
Code:
LIKES(drinker,beer);
FREQUENTS(drinker,bar);
SERVES(bar,beer,cost);
The question is:
Code:
Find bars that serve at least one beer liked by Joe, but do not serve any beer liked by
Michael.
Here is what I have:
Code:
SELECT S.bar
FROM LIKES L, SERVES S
WHERE L.beer = S.beer AND L.drinker='Joe'
EXCEPT 
SELECT S.bar
FROM LIKES L , SERVES S
WHERE L.beer = S.beer AND L.drinker='Michael'
Does this look ok? I am not sure if this enforces the 'at least one beer' constraint.
Reply With Quote
  #2 (permalink)  
Old 10-07-11, 11:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
that looks okay to me

what happened when you tested it?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-07-11, 12:20
tsmith tsmith is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
Hi
I haven't tested it as its a written assignment.
Reply With Quote
  #4 (permalink)  
Old 10-07-11, 12:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
gee, that's too bad

couldn't you just test it anyway?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-07-11, 12:55
tsmith tsmith is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
ok, just tested it in pgAdmin and it seems to work fine. I'll do some more checks now.

If I have to implement a constraint such as the bar has to serve at least 2 beers they like how would I do that?
Reply With Quote
  #6 (permalink)  
Old 10-07-11, 14:40
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
That's not technically a constraint, it's just a business rule. Constraint has a different meaning in DB-land so it might be confusing to say it that way.


Anywho, have a look at GROUP BY, COUNT and HAVING. You need to use those to satisfy the requirements given.
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
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