Imagine we have a table ‘user’ with several different column. Two of them are date (date) and isValid (boolean). I would like to write sql what sort this by two columns (date and isValid). First of all i would like to sort by date ASC, then every row what has isValid = 1 should be after all row with isValid = 0. So even if have a row with date = 2022.01.01 with isValid = 0 should be before row with date 2021.01.01
Initial Data:
Date IsValid
2023 0
2022 1
2025 0
2024 1
2026 0
Expected Data:
Date IsValid
2023 0
2025 0
2026 0
2022 1
2024 1
>Solution :
With a comma between the columns…
SELECT
date,
isValid
FROM
yourTable
ORDER BY
isValid,
date