locked
Create a view that gets all rows from one table, then removes results if the same ID is in another table RRS feed

  • Question

  • User1953081067 posted

    Hi,

    I'd like to create a VIEW (SQL) which first selects all the rows in table 1, then if the ID in table 1 matches the ID in table 2, remove it from the results shown in the VIEW.

    For example, if table 1 have ID's 1 - 5, and table 2 had the ID's 2 and 3, the VIEW would show ID's 1,4,5

    I really hope that makes sense!

    Thanks as always

    Monday, May 7, 2018 7:13 PM

Answers

  • User2053451246 posted
    SELECT *
    FROM Table1 as t1
    WHERE
    	t1.Id NOT IN (SELECT t2.Id FROM Table2 AS t2)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 7, 2018 7:38 PM