April 8, 2021 at 8:37 pm
Hello:
What is the best way to sort a query based on defined priorities in another table.
I have my main 'Schedule' table here...
And I want to sort the WorkCenterID column by the values in this table, 'Operations'.
I am playing around a little with Joins, but I'm not even sure I'm on the right track.
SELECT Schedule.JobID, Schedule.WorkCenterID, Schedule.ProcessID, Operations.Operation, Operations.OpOrder, Schedule.EstimatedProductionHours, Operations.OpOrder
FROM Schedule INNER JOIN
Operations ON Schedule.ProcessID = Operations.Operation
ORDER BY Operations.OpOrder
Thanks!
Steve Anderson
April 8, 2021 at 8:41 pm
That's correct. You don't even need to include Operations.OpOrder in the SELECT results and you can still ORDER BY it.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
April 9, 2021 at 7:26 am
I believe that your join should be
FROM Schedule INNER JOIN
Operations ON Schedule.WorkCenterID = Operations.Operation
April 10, 2021 at 2:48 pm
That's correct. You don't even need to include Operations.OpOrder in the SELECT results and you can still ORDER BY it.
Except when you use DISTINCT or GROUP BY - and some other query constructs, then - SQL requires the column in the order by to be in the select list.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
April 12, 2021 at 8:44 pm
Thank you!
Steve Anderson
April 12, 2021 at 8:44 pm
Thank you.
Steve Anderson
May 18, 2021 at 8:03 am
This was removed by the editor as SPAM
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply