I have a bit of a difficult problem. I need to join two tables together, but if there is no matching right-hand record it needs to select a "default record".
It's for a work registration package where I need to join on a "work factor" table. I have about 200 kinds of work, and about 10 of them have a factor. The rest should link to a default factor. The table with the factors holds a foreign key to the table with the actual work.
-- Work -- -- Factor --
Name WorkID WorkID Factor
Type 1 1 0 1 // DEFAULT
Type 2 2 1 1.5
Type 3 3 2 1.2
3 1.1
Type 4 4
Resulting in
Type 1 1.5
Type 2 1.2
Type 3 1.1
Type 4 1 // DEFAULT
This expands to a table that contains the actual work done on the workfloor, but if I can get this going that won't be much of a problem.
Is this possible with SQL?