Home Forums SQL Server 2008 T-SQL (SS2K8) How to determine which items in one table do not appear in a second table RE: How to determine which items in one table do not appear in a second table

  • You are missing some data here. How can you tell an actionid for an item has been completed when the first table doesn't have ItemIDs? You have two actionIds of "1" for different items.

    Please also ask the question with DDL like this, so people can help you run tests.

    CREATE TABLE ActionEmp

    ( ActionID int

    , EmployeeResponsible int

    )

    ;

    go

    INSERT ActionEmp SELECT 1, 12345;

    INSERT ActionEmp SELECT 2, 67890;

    INSERT ActionEmp SELECT 3, 54321;

    INSERT ActionEmp SELECT 4, 09876;

    go

    CREATE TABLE Actions

    ( ItemID int

    , ActionID int

    )

    ;

    go

    INSERT Actions SELECT 1, 1;

    INSERT Actions SELECT 1, 2;

    INSERT Actions SELECT 2, 4;

    INSERT Actions SELECT 3, 1;

    INSERT Actions SELECT 3, 2;

    INSERT Actions SELECT 3, 3;

    GO

    SELECT

    a.ItemID

    , ae.ActionID

    , ae.EmployeeResponsible

    from ActionEmp ae

    LEFT OUTER JOIN Actions a

    ON ae.actionid = a.actionid

    ORDER BY

    a.ItemID

    , ae.actionid

    ;