NOTE: In hindsight, I realize this may seem like a stupid question, but I really did research it quite a bit before posting here. It was just one of those “right-under-your-nose” kind of answers, ugh!
I have tried to combine multiple simple lookup tables into one as I’ve been told is common practice. I have combined a table containing Statuses and one containing Priority levels as follows:
StatusPriority( ID, Name )
Projects( ID, ProjectName, StatusID, PriorityID ) --Master table
The values for ID between 1-10 represent my statuses while the values for ID between 11-20 represent the priority levels. If I were to split these into two table they would be:
Status( ID, StatusName )
Priority( ID, PriorityName )
GOAL
What I want to do is query for these values into two different columns in the result set with joins to a master table called “Projects.” I tried the following query, but it doesn’t work:
select ProjectName, Name as Status, Name as Priority
from Projects p left outer join
StatusPriority st on p.StatusID = st.Name left outer join
StatusPriority pr on p.PriorityID = pr.Name
SAMPLE RESULTS
ProjectName | Status | Priority
--------------------|---------------|-----------
Pick Blueberries | on hold | medium
Remodel bathroom | in progress | low
Plant garden | in progress | high
You’re criteria for the joins looks wrong, as p.StatusID I can’t imagine would be equal to st.Name. secondly you need to use your table aliases on the select list: