Sorry if the title was sort of vague was unsure how to phrase it.
I currently am choosing values for a field from table like so (clickable SqlFiddle link included):
`Select `ID`,IF(`SpecificationID` is NULL,'0', `SpecificationID`) from Orders;`
http://www.sqlfiddle.com/#!9/b8108b/8
Which as you can see pulled the SpecificationID from the Orders table and if it found a NULL pulled 0
. I get that I could/should make the default values in my table = 0
yet to do so would require multiple code changes so this was the easiest way to pull 0
for NULL values which I ultimately need for this process.
It turned out that Orders can have multiple Specifications so I created a Look-Up-Table with OrderID and SpecificationID
My new query therefor looks liks this:
Select `OrderID`,`SpecificationID` from LUT_Orders_Specifications
order by OrderID;
http://www.sqlfiddle.com/#!9/b8108b/9
The issue is that since the LUT only stores values for records with an OrderID I don't get OrderIDs which have no values and therefore don't get 0
for them.
I am unsure how/if I can do a Join that will get the values from the LUT and also return 0
for the records that are not in the LUT.
I know how to select IDs that are not in a table e.g.
Select ID from Orders where ID not in
(Select T1.OrderID from LUT_Orders_Specifications T1
Inner Join Orders T2
on T1.OrderID=T2.ID)
http://www.sqlfiddle.com/#!9/b8108b/15
But I am unclear how I can combine the processes so I am grabbing all the specification values for a single order and a 0
value for an order that has no specifications.