SQL Server, selecting from 2 columns from different tables -
I have 2 tables from these tables
Table 1 Table 2 Code ID code ID A1a1b1b1c1c1d1e1
my query:
select a.id, a.code, b Cod table 1a, table 2b where a.id = '1' and a.id = b.id
what I expected
Code code 1 aa1b1 1 c 1d tap 1e null
what i found
id code code 1 aa1bah1cA1dA 1 EA1 AB1BB1 CB ....
Any ideas?
OK, both the IDs are in both tables by joining on the ID to 1, then you have both tables The Cartesian product will be found.
Instead, you will need to insert a left exterior based on Table1.Code
. :
Select a.id, a.code, b code from Table1, to a left OUTER on Table2b on a cod = b.code where a.id = '1';
Comments
Post a Comment