SQL View where rows not mapped
-
13-12-2019 - |
Question
Basically what I'm trying to figure out is, Say I have
table 1tbl1
ID | Name
and table2tbl2
ID | Name
Then I have a mapping table mt
ID | tbl1ID | tbl2ID
Data really isn't important here, and these tables are examples.
How to make a view
that will grab all the items in tbl1
that aren't mapped to mt
.
I'm using Microsoft SQL-server 2008 by the way.
Solution
CREATE VIEW v_unmapped
AS
SELECT *
FROM tbl1
WHERE id NOT IN
(
SELECT tbl1Id
FROM mt
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow