Items not returned from a list

0

Please login or register to vote for this query.

(click on this box to dismiss)

Economics

Q&A for those who study, teach, research and apply economics and econometrics

CREATE TABLE #tableA
(
  [Item] INT
)

INSERT INTO #tableA ( [Item] ) VALUES (1)
INSERT INTO #tableA ( [Item] ) VALUES (2)
INSERT INTO #tableA ( [Item] ) VALUES (3)
INSERT INTO #tableA ( [Item] ) VALUES (4)
INSERT INTO #tableA ( [Item] ) VALUES (5)
INSERT INTO #tableA ( [Item] ) VALUES (6)

SELECT
  *
FROM
  #tableA
WHERE
  [Item] IN (4, 5, 6, 7, 8)

CREATE TABLE #List
(
  [ListItem] INT
)

INSERT INTO #List ( [ListItem] ) VALUES (4)
INSERT INTO #List ( [ListItem] ) VALUES (5)
INSERT INTO #List ( [ListItem] ) VALUES (6)
INSERT INTO #List ( [ListItem] ) VALUES (7)
INSERT INTO #List ( [ListItem] ) VALUES (8)

SELECT
  *
FROM
  #List AS l
LEFT OUTER JOIN
  #tableA AS t
ON
  t.[Item] = l.[ListItem]
WHERE
  t.[Item] IS NULL

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results