troubleshooting Question

Writing a sorting query involving two tables

Avatar of buttonMASTER
buttonMASTER asked on
3 Comments1 Solution61 ViewsLast Modified:
I have two tables that looks like this:


Name               Type               
------------------ ------------------ 
ID                 NUMBER
Data               DOESN'T_MATTER


Name               Type               
------------------ ------------------ 
ID                 NUMBER
Reference_ID       NUMBER
Order              NUMBER

The values in that Data_table are:

ID		data
1		value_1
2		value_2
3		value_3
4		value_4
5		value_5

The values in the Sort_Table are:

ID		reference_id	order
1		2		2
2		3		1
3		5		3

Where the reference ID refers to the ID in the data_table.

I need a query to get the IDs from the Data_table in the order defined in the sort_table, but if anything from the data_table doesn't show up in the sort_table I want it to show up at the end like this:

1 -- this isn't in sort_table
4 -- this isn't in sort_table
Pavel Celba
All in One

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros