I have a below Organisation table.
ID | Resource |
---|---|
1 | Software Engineer |
2 | Tech Lead |
3 | Architect |
4 | Senior Software Engineer |
5 | HR |
I need to fetch this table using select query such that the output which i receive should have ID 4 between ID 1 and ID 2
Output:
ID | Resource |
---|---|
1 | Software Engineer |
2 | Tech Lead |
4 | Senior Software Engineer |
3 | Architect |
5 | HR |
How can i achieve this
3
Answers
You could use a
CASE
expression to generate the ordering you want:You can use a
SELECT
query with anORDER BY
clause to specify the order in which the rows should be displayed.It seems like you’re trying to retrieve specific rows from your Organization table based on the ID. To achieve this, you can use the ORDER BY clause along with a CASE statement in your SQL query. Here’s your query:
This query will prioritize the row with ID 4 to be placed after ID 1. The rest of the rows will be ordered based on their IDs.