Jump to content

Table join question


elmpp

Recommended Posts

I have this question to answer as part of a job application, so i would be very grateful if i could get some help!!

 

The question in question is number 2c at this link:

 

http://www.freecaradverts.com/red_snapper_test.pdf

 

I know this is a bit cheeky, but I\'m desparate to get this done. Is this possible within MySQL (i\'m trying it with that). I\'ve tried comparing the tables with an

 if(SUBSCRIPTION.paperid=PAPER.paperid, \'True\', \'False\') 

but can\'t seem to just get the 5 returned rows. Help!!!!!!!!!!!!

:x

Link to comment
Share on other sites

select papername, IF(personid is null,\'False\', \'True\') as subscribed

from paper

left outer join subscription on paper.paperid=subscription.paperid

and subscription.personid =1

order by papername

 

The important things:

 

-use left outer join to get a row whether or not Jacque is subscribed

-use AND to only get rows from subscription that are Jacque (personid =1). Since a person can only be subscribed to a paper once, this means that we either get a personid of 1, or NULL in the personid column.

-use IF on personid to test for NULL (ie a paper that Jacque is not a subscriber to)

 

 

Don\'t say I never did anything for ya :wink:

Now if you get the job, will I be getting a kickback from you?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.