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

  • OK, sorry, let me try to explain more fully. The Action Table contains actions that need to be completed for each Item and the person responsible for taking the action. It is essentially a lookup table. So:

    CREATE TABLE Actions

    ( ActionID int,

    ActionName varchar(30),

    , EmployeeResponsible int

    )

    ;

    go

    INSERT Actions SELECT 1, 'Emails Sent', 12345;

    INSERT Actions SELECT 2, 'Emails Archived', 67890;

    INSERT Actions SELECT 3, 'Project Folder Archived', 54321;

    INSERT Actions SELECT 4, 'Acknowledged Notification', 09876;

    go

    The Items table contains items for which each of the 4 actions must be completed. There can be a maximum of 4 rows per item, i.e., one row for each action. So:

    CREATE TABLE Items

    ( ItemID int

    , ActionID int

    )

    ;

    go

    INSERT Items SELECT 1, 1;

    INSERT Items SELECT 1, 2;

    INSERT Items SELECT 2, 4;

    INSERT Items SELECT 3, 1;

    INSERT Items SELECT 3, 2;

    INSERT Items SELECT 3, 3;

    GO

    So, for Item 1, Actions 1 and 2 have been completed, but not Actions 3 and 4. For Item 2, only Action 4 has been completed. For Item 3 all actions except Action 4 have been completed. I want a result set that reflects the uncompleted action IDs for each ItemID:

    ItemID ActionID

    1 3

    1 4

    2 1

    2 2

    2 3

    3 4

    Thanks!