Results 1 to 2 of 2

Thread: Select Statement that join to different tables based on Field Contents

Threaded View

  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Select Statement that join the main table to different tables based on Field Contents

    Purpose of Post: To create a SELECT statement that returns results from multiple tables, choosing which tables to retrieve values from based on NULL fields within the main (comics) or intermediate (ComicLinks, ComicIDs) tables.
    Database: MySQL 4.1.20
    Database Structure: See attached image.


    Rows that will always be selected:

    Number, Semester, CavDaily_Edition, Comic, Drawn, Commentary, Comic_Page, Notes

    Underlined fields may be null, but I have PHP code set up to handle null fields.
    The field Comic_Page functions as a boolean value.

    "IF Statements that alter what the select statement returns

    IF Comics.RegDateID IS NULL
    • NOT NULL: SELECT WeekDay, Month, Day, Year FROM RegDate join Comics on RegDate.RegDateID = Comics.RegDateId
    • NULL: SELECT DateText FROM OddDate join Comics on OddDate.OddDateID = Comics.OddDateId


    IF Comics.Number IN (SELECT Number FROM ComicLinks)
    • TRUE: SELECT LinkTitle, Linkhref FROM Links JOIN ComicLinks ON Links.LinkID = ComicLinks.LinkID JOIN Comics ON Comics.Number = ComicLinks.Number
    • FALSE: (No Select Statement)


    IF ComicIDs.SoloID IS NULL
    • NOT NULL: SELECT ComicTitle FROM Standalones join ComicIDs on ComicIDs.SoloID = Standalones.SoloID join Comics.ComicID = ComicIDs.ComicID
    • NULL: SELECT StoryTitle, StoryNum FROM Storylines join ComicIDs on ComicIDs.StoryID = Standalones.StoryID join Comics.ComicID = ComicIDs.ComicID



    How do I set up the mysql query to do this? It will be used in a PHP-based webpage, but I want to rely on PHP as little as possible so as to speed up the processing of the page.
    Attached Images Attached Images
    Last edited by Mr Initial Man; 12-01-2007 at 02:24 PM. Reason: Made the title clearer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •