I have a table mytable
id | name| location
---|-----|----------
1 | fff | www
2 | bbb | xxx
3 | aaa | www
4 | eee | xxx
5 | ddd | yyy
6 | ccc | xxx
How do I select it such that I get the names arranged in ascending order separated by their location ?
I am expecting output to be :
name| location
-----|----------
aaa | www
fff | www
bbb | xxx
ccc | xxx
eee | xxx
ddd | yyy
The sql :
SELECT name, location
FROM mytable
GROUP BY location
ORDER BY location, name ASC
gives :
name| location
-----|----------
bbb | xxx
ddd | yyy
fff | www
In this case you don’t need to use GROUP BY , only:
It will give you your expected results