Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    70

    Unanswered: SQL Select statement and LEFT OUTER JOIN and 3 tabls, please help =(

    SQL is definitely not my strong point. I need to add a column to an existing select statement that looks like this:
    --------------

    SELECT A.ID, A.SCHEDSTARTDATE, A.DBID, B.NAME, ...about 12 more columns all from the A table...
    FROM FirstTable A, SecondTable B
    WHERE A.STATE = B.ID

    -------------
    I have to join that with a third table and get just one column. Im guessing this will be a LEFT OUTER JOIN as the additional column is only present on some of the corresponding A rows.

    So I thought it would look like this:
    ---------------
    SELECT A.ID, A.SCHEDSTARTDATE, A.DBID, B.NAME, ...those 12 columns all from A..., C.NAME_HOST
    FROM SecondTable B,
    (FirstTable A
    LEFT OUTER JOIN ThirdTable C
    ON A.DBID = C.DBID)
    WHERE A.STATE = B.ID
    ---------------

    That doesnt return an error but its grabbing tons of documents, way more than original so obviously its wrong. Is the "WHERE A.STATE = B.ID" just completely off?

    Any help would be greatly appreciated

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    I think what you want is:

    SELECT A.ID, A.SCHEDSTARTDATE, A.DBID, B.NAME, ...those 12 columns all from A..., C.NAME_HOST
    FROM FirstTable A INNER JOIN ON (a.state = b.ID)
    LEFT OUTER JOIN ThirdTable C
    ON A.DBID = C.DBID

    HTH

    Andy

  3. #3
    Join Date
    Jan 2004
    Posts
    70
    That worked great, thank you very much for the prompt reply, now I just gotta go hound someone who actually knows the data for info on how to join the 4th table

Posting Permissions

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