SELECT subset from two tables and LEFT JOIN results
Posted
by Doctor Trout
on Stack Overflow
See other posts from Stack Overflow
or by Doctor Trout
Published on 2010-05-03T17:32:47Z
Indexed on
2010/05/03
17:38 UTC
Read the original article
Hit count: 264
Hi all,
I'm trying to write a bit of SQL for SQLITE that will take a subset from two tables (TableA and TableB) and then perform a LEFT JOIN.
This is what I've tried, but this produces the wrong result:
Select * from TableA
Left Join TableB using(key)
where TableA.key2 = "xxxx"
AND TableB.key3 = "yyyy"
This ignore cases where key2="xxxx" but key3 != "yyyy".
I want all the rows from TableA that match my criteria whether or not their corresponding value in TableB matches, but only those rows from TableB that match both conditions.
I did manage to solve this by using a VIEW, but I'm sure there must be a better way of doing this. It's just beginning to drive me insane tryng to solve it now.
(Thanks for any help, hope I've explained this well enough).
© Stack Overflow or respective owner