I have two tables, A and B.
Fields of A: id, name
-----------------
ID | NAME |
-----------------
1 | name1 |
-----------------
2 | name2 |
-----------------
3 | name3 |
-----------------
4 | name4 |
-----------------
5 | name5 |
-----------------
Fields of B: bid, id
-----------------
BID | ID |
-----------------
11 | 1 |
-----------------
11 | 2 |
-----------------
12 | 1 |
-----------------
12 | 2 |
-----------------
12 | 3 |
-----------------
I want to perform a query to show ALL records from A with columns A.id, A.name on the left. And join a third column from B ON id WHERE bid = ’11’.
So I would have something like this:
--------------------------------
A.ID | A.NAME | B.BID
--------------------------------
1 | name1 | 11
--------------------------------
2 | name2 | 11
--------------------------------
3 | name3 |
--------------------------------
4 | name4 |
--------------------------------
5 | name5 |
--------------------------------
Any suggestions?
You will want to use a
LEFT JOINSee SQL Fiddle With Demo
Based on your update, you will want to move the filter from the
WHEREclause to theJOIN:See SQL Fiddle with Demo