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

  • There are probably better ways, but I think this works:

    ; WITH AllActions (ItemID, ActionID)

    AS

    (

    SELECT distinct

    i.itemid

    , a.actionid

    FROM items i

    CROSS APPLY

    ( select a.actionid

    FROM Actions a

    ) a

    )

    SELECT

    *

    FROM AllActions aa

    WHERE aa.itemid NOT IN (select i.itemid

    FROM items i

    WHERE aa.itemid = i.ItemID

    AND aa.ActionID = i.ActionID

    )

    ORDER BY

    itemid

    , ActionID