Answer the question
In order to leave comments, you need to log in
How to sort in sql query by two conditions for two selections?
I have a table with this content
id |guid |sort|
------|------------------------------------|----|
239980| | 1|
354533|666a9a7d-b2ed-11eb-8b8b-9c5c8e4f1f67| 0|
354538| | 2|
354540|787a9a7d-b2ed-11eb-8b8b-9c5c8e4f1f67| 1|
SELECT id,guid,sort from images where model_id = 102188 and guid is not null order BY sort DESC;
id |guid |sort|
------|------------------------------------|----|
354540|787a9a7d-b2ed-11eb-8b8b-9c5c8e4f1f67| 1|
354533|666a9a7d-b2ed-11eb-8b8b-9c5c8e4f1f67| 0|
SELECT id,guid,sort from images where model_id = 102188 and guid is null order BY sort DESC;
id |guid|sort|
------|----|----|
354538| | 2|
239980| | 1|
id |guid |sort|
------|------------------------------------|----|
354540|787a9a7d-b2ed-11eb-8b8b-9c5c8e4f1f67| 1|
354533|666a9a7d-b2ed-11eb-8b8b-9c5c8e4f1f67| 0|
354538| | 2|
239980| | 1|
SQL Error [1221] [HY000]: Incorrect usage of UNION and ORDER BYwhen using UNION, you cannot use ORDER BY - actually, how can I do what I want?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question