Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL query using two tables plus a third for linking them

  • 27-10-2010 9:48am
    #1
    Registered Users, Registered Users 2 Posts: 1,231 ✭✭✭


    Hi Guys,

    Sorry if this the wrong place for SQL questions. My xbox downloads tv shows automatically at night using an RSS feed. It then scrapes thetvdb.com to get information about the show and enters this information into a sqlite db.

    I am going to create a script that emails me in work informing me what was downloaded the previous night including a synopsis of the episode. I then know what I will be watching in the evening.

    The problem is pulling the correct information out of the db to email to myself.

    The three tables are:

    http://wiki.xbmc.org/index.php?title=The_XBMC_Database#episode
    http://wiki.xbmc.org/index.php?title=The_XBMC_Database#tvshow
    http://wiki.xbmc.org/index.php?title=The_XBMC_Database#tvshowlinkepisode

    The last table links the primary keys of the first two db's together.

    How do I go about this? I think it should be like ...

    select episode.c00, episode.c01 , episode.c05, c00.tvshow
    join tvshowlinkepisode.idShow tvshowlinkepisode.idEpisode
    where episode.c05='some date'

    Any help pointing me in the correct direction is very much appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 67 ✭✭The Gibmiester


    I have no way of testing this but try
    SELECT episode.coo, episode.co1, episode.co5, tvshow.c05 
    FROM episode, tvshow, tvshowlinkepisode
    WHERE episode.idEpisode = tvshowlinkepisode.idEpisode
    AND tvshow.idshow = tvshowlinkepisode.idshow
    

    You can then add another AND for episode.c05='some date'


  • Registered Users, Registered Users 2 Posts: 1,231 ✭✭✭stereo_steve


    Brilliant Gibmeister, thats alot. It worked straight away.

    The bit linking the two primary keys was confusing me. It's nice to have a working example.

    One last question, for the line ...

    AND episode.c05='some date'

    Is it possible to input some kind of date variable so that yesterday will be queried? In the format yyyy-mm-dd. If not I'll work around it with the script.

    Thanks again


  • Registered Users, Registered Users 2 Posts: 11,998 ✭✭✭✭Giblet


    Try

    SELECT date('now','-1 day');

    Can be used like

    where date > date('now','-1 day');


  • Registered Users, Registered Users 2 Posts: 1,231 ✭✭✭stereo_steve


    Thanks Guys, Its working perfectly now. I learnt some SQL in the process


Advertisement