imstillatwork
IS-IT--Management
This question is about using left joins, and a where constrain on a field in the joined table.
I I have a really simple query like so...
so something like this works great. but if there are no matching rows in tableB, I don't even get my data from tableA, which I still need...
The sql above makes sense, and the reason I don't get the data from tableA makes sense too...
but what do I do if I want to get the data from tableA even if there is no data in tableB matching the WHERE claus?
I mean, I am using a left join because I want tableA data even if there is none in tableB. but as soon as you constain it to a condition of tableB in the WHERE clause, that 'theory' dies...
I I have a really simple query like so...
Code:
SELECT
a.field1a
,b.field1b
FROM tableA as a
LEFT JOIN tableB as b
ON a.id = b.a_id
WHERE b.this = 1
so something like this works great. but if there are no matching rows in tableB, I don't even get my data from tableA, which I still need...
The sql above makes sense, and the reason I don't get the data from tableA makes sense too...
but what do I do if I want to get the data from tableA even if there is no data in tableB matching the WHERE claus?
I mean, I am using a left join because I want tableA data even if there is none in tableB. but as soon as you constain it to a condition of tableB in the WHERE clause, that 'theory' dies...