OUTER JOIN - Help, I''m stumped

  • Good Afternoon,

    Forgive the lengthy discourse, but I want to provide as much information as possible so that someone will be able to help me out.  This question concerns getting an outer join to work the way that I expect it to:

    Table A - tblSOPType

    Id     Description

    1      Startup SOP

    2      Shutdown SOP

    3      Emergency Shutdown

    4      Post Emergency Startup

     

    Table B - tblSOPS

    ID     tblEquipment_ID      tblSOPType_ID

    1      1                          1

    2      1                          2

    3      2                          1

    3      2                          1

     

    What I want to do is produce a query that gives me the following results:

    sqlQuery Results

    tblSOPS_ID     tblEquipment_ID    tblSOPType_ID

    1                  1                        1

    1                  1                        2

    null               1                        3

    null               1                        3

     

    I have attempted the following query:

    SELECT

     tblSOP_Type.Id,  tblSOPS.tblEquipment_id, tblSOPS.tblSOPType_id

    FROM

    tblSOP_Type

    LEFT

    OUTER JOIN tblSOPS ON tblSOPS.tblSOPType_id = tblSOP_Type.id

    WHERE

     tblEquipment_ID = 1

    I only get the following records:

    1                  1                        1

    1                  1                        2

     

    Any suggestions on how to get the null records where there was no match?

    Thank you ...

     

    dlcollison

  • Try this query:

    SELECT

        tblSOP_Type.Id,

        tblSOPS.tblEquipment_id,

        tblSOPS.tblSOPType_id

    FROM

        tblSOP_Type

        LEFT OUTER JOIN tblSOPS

            ON (tblSOPS.tblSOPType_id = tblSOP_Type.id

                tblEquipment_ID = 1)

    hth!

  • I hope u are trying this:

     

    select * from tblSOP_Type

    LEFT OUTER JOIN tblSOPS ON tblSOP_Type.id = tblSOPS.tblSOPType_id

    thanks

    Sreejith

  • Journeyman ...

    You DA man!!!!!

    Worked like a charm

    Thanks ...

    dlcollison

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply