Reputation: 21
Sorry I tried searching for the answer and getting stuck
I am trying to inner join two tables to pull a value e.g.
table 1
--------
column a
column b
column c
table 2
--------
column a
column d
So, I want to pull all columns from table 1
and then, where column a
appears in table 2
, I want to pull column d
Just not sure if inner join is right or how to write it
Upvotes: 2
Views: 1575
Reputation: 1647
select table1.*, table2.d from table1 left join table2 on table1.a = table2.a
Upvotes: 0
Reputation: 8882
There are four types of join:
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
as listed on http://www.w3schools.com/sql/sql_join.asp
You want a LEFT JOIN from your description
SELECT table1.*, table2.d FROM table1 LEFT JOIN table2 ON table1.a = table2.a
Upvotes: 3