How to upload from the database first one condition and then another in the same query?

For example, there is the query:
SELECT *
FROM table
WHERE 1
ORDER BY field1 DESC, field2 ASC
It is first sorted by field1 and then by field2. Is it possible to do similarly to first unload record in one condition (e.g., field1=0), and then by another condition (for example, field2=1) and all this in a single query?
April 3rd 20 at 18:51
4 answers
April 3rd 20 at 18:53
Solution
Can you?
SELECT *
FROM table
WHERE field1=0 OR field2=1
ORDER BY field1=0 DESC, field1 DESC, field2=1 DESC, field2 ASC
Thank you very much, this turned out to do something)) - chet.Joh commented on April 3rd 20 at 18:56
April 3rd 20 at 18:55
No, that is impossible.
Run the queries separately, and then treat and give the user data.
April 3rd 20 at 18:57
SELECT *
FROM `table` t
JOIN (SELECT 0 AS c UNION SELECT 1) AS _iter ON 1 = 1
WHERE ((t.field1 = 0 AND _iter.c = 0) OR (t.field2 = 1 AND _iter.c = 1))
ORDER BY _iter.c
April 3rd 20 at 18:59
(SELECT `field1`, `field2`, 0 AS `order`
 FROM `table`
 WHERE `field1` = 0)
UNION (SELECT `field1`, `field2`, 1
 FROM `table`
 WHERE `field2` = 1)
ORDER BY `order`

Just keep in mind that some lines cannot be uploaded twice - for each of the conditions.

Find more questions by tags MySQL