sql server - SQL Joining different tables structure (MSSQL) -
i have different tables , want join information. in case have product, sales , product definition table.
product table:
productid | name 1 | product 1 2 | product 2 3 | product 3
product definitions table:
defid | productid | column 1 | column 2 | .... 001 | 1 | text | text 002 | 1 | text | text 003 | 3 | text | text 004 | 2 | text | text 005 | 3 | text | text
sales table:
salesid | productid | sales 01 | 1 | 13 02 | 1 | 12 03 | 2 | 1 04 | 2 | 4 05 | 3 | 2
i want replace information (e.g. product definition -> sales) not existing -1. , create query view:
defid | productid | salesid | sales | column 1 | column 2 | .... 001 | 1 | -1 | -1 | text | text 002 | 1 | -1 | -1 | text | text 003 | 3 | -1 | -1 | text | text 004 | 2 | -1 | -1 | text | text 005 | 3 | -1 | -1 | text | text -1 | 1 | 01 | 13 | - | - -1 | 1 | 02 | 12 | - | - -1 | 1 | 03 | 1 | - | - -1 | 2 | 04 | 4 | - | - -1 | 3 | 05 | 2 | - | -
try this:
select defid, productid, -1 salesid, -1 sales, column1 , column2 productdefinition union select -1 defid, productid, salesid,sales, '-' column1 ,'-' column2 sales
Comments
Post a Comment