Reputation: 3667
I want to create a new table from 3 tables:
All these tables are linked by ID
column.
I know I will need a vertical join (UNION).
Query:
How do I use the UNION join to look up values, from table1 and keep all records from table2?
Upvotes: 0
Views: 91
Reputation: 175606
You could use:
--CREATE VIEW my_view AS
SELECT sub.id, sub.col1, sub.col2, table3.col1, ...
-- INTO #temp_table -- alternatively
FROM (SELECT id,col1, col2, ... -- only common column list, drag and drop from
FROM table1 -- object explorer
UNION
SELECT id, col1, col2, ...
FROM table2) sub
JOIN table3 ON table3.id = sub.id
WHERE table3.date >= '2010-10-01'
Upvotes: 1