Hi, i have table with column that takes country name else it takes "other" value my question is how i can retrieve rows grouped by country name and the rows with country name equal to "other" are in the end of selection
Printable View
Hi, i have table with column that takes country name else it takes "other" value my question is how i can retrieve rows grouped by country name and the rows with country name equal to "other" are in the end of selection
Easiest way would probably beQuote:
Originally Posted by ledaker
Code:SELECT *
FROM tableA
WHERE columnA <> 'Other'
ORDER BY columnA asc
UNION
SELECT *
FROM tableA
WHERE columnA = 'Other';
Hi all.
This query doesn't work beacause you cannot add the ORDER BY clause into UNION. Probably there isn't a way to get what ledaker wants using only a query.
davide++ has reason this query doesnt work, please other solutionQuote:
Originally Posted by davide++
Sorry, you're right, try this instead
Just note that you'll get the extra field out "OrderBy" with values '1' or '2'.Code:SELECT *, '1' AS OrderBy
FROM tableA
WHERE columnA <> 'Other'
UNION
SELECT *, '2' AS OrderBy
FROM tableA
WHERE columnA = 'Other'
ORDER BY OrderBy ASC;
thank you :wave: