SQL Query基于来自2个表的引用从第二个表中提取列值

时间:2013-05-01 16:28:24

标签: sql-server-2008

抱歉,我试着寻找答案并陷入困境

我正在尝试内连接两个表来拉取一个值,例如

table 1
--------
column a
column b
column c

table 2
--------
column a
column d

所以,我想从table 1中提取所有列,然后column a中出现table 2,我想提取column d

不确定内连接是否正确或如何编写

2 个答案:

答案 0 :(得分:3)

有四种类型的连接:

JOIN: Return rows when there is at least one match in both tables
LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
FULL JOIN: Return rows when there is a match in one of the tables

列在http://www.w3schools.com/sql/sql_join.asp

您想要从描述中获得LEFT JOIN

SELECT table1.*, table2.d FROM table1 LEFT JOIN table2 ON table1.a = table2.a

答案 1 :(得分:0)

select table1.*, table2.d from table1 left join table2 on table1.a = table2.a