I have two tables:
The first one having the columns:
|Name | Company | Job|
with values such as
(jack apple developer),
(Julian google developer),
(Jim eBay developer),
(jack apple janitor),
(Julian google janitor),
(Jim eBay janitor),
(jack apple manager),
(Julian google manager),
(Jim eBay manager)
and the second table consists of the sort order of name and job with columns
|FilterVal | Name_Sort_Order | Job_Sort_Order|** and Values
(jack,2, NULL),
(Julian, 1, NULL),
(Jim, 3, NULL),
(Janitor, NULL, 1),
(Manager, NULL, 3),
(Developer, NULL, 2)
How would I sort the first table by name_sort_order and job_sort_order of the second table?
desired result:
(Julian google janitor),
(Julian google developer),
(Julian google manager),
(jack apple janitor),
(jack apple developer),
(jack apple manager),
(Jim eBay janitor),
(Jim eBay developer),
(Jim eBay manager)
2
Answers
Hmmm . . . one method uses subqueries in the
order by
:You can join second table twice (based on column ‘FilterVal’) and then order by. Crucial here is aliasing second table.