2011-06-08 170 views
0
Table 1 
id - name 
1 - ric 
2 - joe 
3 - harry 
4 - james 

Table 2 
sno - Tbl_1_Id - notes 
1 - 1  - abcdef 
2 - 4  - xyzzz 

我需要幫助的結果是需要使用SQL查詢

id - name - notes 
1 - ric - abcdef 
2 - joe - 
3 - harry- 
4 - james- xyzzz 

回答

2
SELECT t1.id, t1.name, t2.notes 
FROM  Table1 t1 
     LEFT OUTER JOIN Table2 t2 ON t1.id = t2.Tbl_1_Id 
2

使用左連接。

SELECT t1.id, t1.name, t2.notes FROM 
table1 as t1 
LEFT JOIN table2 as t2 ON (t1.id = t2.tbl_1_id)