Let’s suppose I have three different select statements, like this
SELECT 'Final', ID FROM Stage WHERE stageCompleted = 1;
SELECT 'Active', ID FROM Stage WHERE StartDate < NOW();
SELECT 'Inactive', ID FROM Stage;
What I would like is some way of combining these such that it displays one table that
- returns the string
'Final'and the ID of the row for all of the rows matched by the first query - returns the string
'Active'and the ID of the row for all of the rows matched by the second query but not by the first - and returns the string
'Inactive'and the ID of all the remaining rows.
I looked into all sorts of joins, but they don’t seem to really fit the problem I’m trying to solve. How can I combine three select queries in SQL, where each one excludes the results from the previous ones?
Use a case statement