Click to See Complete Forum and Search --> : [RESOLVED] access problem


ledaker
October 26th, 2008, 05:58 PM
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

Homogenn
October 27th, 2008, 05:15 AM
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 be


SELECT *
FROM tableA
WHERE columnA <> 'Other'
ORDER BY columnA asc

UNION

SELECT *
FROM tableA
WHERE columnA = 'Other';

davide++
October 27th, 2008, 11:23 AM
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.

ledaker
October 27th, 2008, 03:34 PM
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 solution

Homogenn
October 28th, 2008, 03:01 AM
Sorry, you're right, try this instead


SELECT *, '1' AS OrderBy
FROM tableA
WHERE columnA <> 'Other'

UNION

SELECT *, '2' AS OrderBy
FROM tableA
WHERE columnA = 'Other'

ORDER BY OrderBy ASC;


Just note that you'll get the extra field out "OrderBy" with values '1' or '2'.

ledaker
October 28th, 2008, 05:22 AM
thank you :wave: