I need a help with a small query.
Table A:- status and the contents of it are below.
status_id status_descrip
1 held
2 release
3 WIP
Table B:- Entry is another table which has some 30 fields. Out of which 2 fields are referring to Table A-> status table. For simplicity i am skipping other fields and jotting down only the fields related with status.
entry_id design_status stress_status
1 3 1
2 1 2
3 NULL 2
4 3 3
5 NULL 1
6 NULL NULL
7 NULL 2
I can’t change the structure of Entry to split into 2 tables one as design_status and other as stress_status.
Now i want the entries from entry table replace the status with their descriptions. so the output will be
entry_id design_status_descrip stress_status_descrip
1 WIP held
2 held release
3 NULL release
4 WIP WIP.
5 NULL held
6 NULL NULL
7 NULL release
Thanks in advance!
EDIT:-
Question is edited with Entries.
Thankyou for all your responses!
and the query finally working for me is,
SELECT b.entry_id, design_status_descrip = d.status_descrip,
stress_status_descrip = s.status_descrip FROM entry AS b
LEFT OUTER JOIN status AS d ON b.design_status = d.status_id
LEFT OUTER JOIN status AS s ON b.stress_status = s.status_id
do let me know, if i can improve this query.
The simplest way would be to join against the status table twice. I’ve used INNER JOIN assuming that the design_status and stress_status columns in your schema have proper constraints. Edited for changed requirements.