I have a statement like
TableA
ID X
1 x1
2 x2
3 x3
TableB
ID AttributeName AttributeValue
1 Type some
2 not nothing
3 Type other
I now want a result like
1,x1,some
2,x2,''
3,x3,other
The SQL
SELECT TableA.ID, TableA.X, TableB.AttributeValue
FROM TableA, TableB
WHERE TableA.ID = TableB.ID AND TableB.AttributeName = 'Type'
gives me all IDs with X and TypeDescription where the Attribute Type exists.
But I also want the IDs where no Type is set included – how to reach that?
You need an outer join:
This will return a
NULL, not an empty string''for id=2. If you need an empty string instead, use coalesce. On SQL Server it would look like this: