I am trying to write a SQL query that does some complex sorting. I have a table with some records, each having three important fields:
- Group_ID
- Modified_Order
- Created_Order
Now, I am trying to write a query that first sorts these by the group ID. Then if the group ID is 1, sort those results by their “modified order”. If the group ID is 2, sort them by their “created order”. Group ID’s that are not 1 or 2 will not occur. In other words, I want the results to look like the picture below.

How can I write the “ORDER BY” or “GROUP BY” part of my query to do this?
1 Answer