我有這列從2個表SQL Server中,從不同的表
從2列選擇Table1 Table2
Code ID Code ID
A 1 A 1
B 1 B 1
C 1 C 1
D 1
E 1
我的查詢:
Select
a.id, a.code, b.code
from
Table1 a, Table2 b
where
a.id = '1' and a.id = b.id
我期待什麼
ID code code
1 A A
1 B B
1 C C
1 D NULL
1 E NULL
我該怎麼
ID code code
1 A A
1 B A
1 C A
1 D A
1 E A
1 A B
1 B B
1 C B
....
有何想法?不同並沒有幫助
感謝
[不良習慣踢:使用舊式聯接(http://sqlblog.com/blogs/aaron_bertrand /archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx) - 舊式*逗號分隔的表*樣式列表被替換爲* proper * ANSI'在ANSI - ** 92 ** SQL標準(**超過20年**前)中加入JOIN'語法,並且不鼓勵使用 – 2014-10-28 07:51:12