*SORRY I MEANT LEFT JOIN *
Probably a basic thing but I cant seem to think of the right keywords to search for it!
I have lookup table I use to return names for various "Sales Class" codes.
It all works good but if there is a code that isn't in the lookup table it leaves that field empty.
I want it to return the word "Unknown" for any code that doesn't have a match.
Here is the SQL:
Table examples:
Data1:
OrderNum - Sales Class
111 - class1
222 - class2
333 - classX
SalesClasses:
Code1 - Name
class1 - Shoes
class2 - Boots
Desired Result:
OrderNum - Name
111 - Shoes
222 - Boots
333 - Unknown
Probably a basic thing but I cant seem to think of the right keywords to search for it!
I have lookup table I use to return names for various "Sales Class" codes.
It all works good but if there is a code that isn't in the lookup table it leaves that field empty.
I want it to return the word "Unknown" for any code that doesn't have a match.
Here is the SQL:
Code:
SELECT [Data1].OrderNum, SalesClasses.[Name]
FROM [Data1]
LEFT JOIN SalesClasses ON [Data1].[Sales Class] = SalesClasses.[Code1];
Table examples:
Data1:
OrderNum - Sales Class
111 - class1
222 - class2
333 - classX
SalesClasses:
Code1 - Name
class1 - Shoes
class2 - Boots
Desired Result:
OrderNum - Name
111 - Shoes
222 - Boots
333 - Unknown
Last edited: