Well interesting to me at least...
Say I have two tables:
myLookUpTable:
lookupId | Name
-------- -----
1 Red
2 Green
3 Blue
and InfoTable:
infoId lookupId Amount ParentId
------ -------- ------ --------
1 1 2 332
2 3 14 332
How would I write a query that returns every row in myLookUpTable
and includes associated information from InfoTable if it exists for a certain ParentId?
Example:
querying for parentId 221 would return The following for Name
and Amount
:
Name Amount
---- ------
Red
Green
Blue
and querying for parentId 332 would return The following for Name
and Amount
:
Name Amount
---- ------
Red 2
Green
Blue 14
I've tried about ten variations of left joins with no luck. Below is my latest:
SELECT mlut.Name, it.Amount
FROM myLookUpTable as mlut
LEFT JOIN InfoTable as it
ON mlut.lookupId = it.lookUpId OR it.ParentId is null
where it.ParentId = 332
This seems like a simple issue, am I just over looking something?