i have a table CITY which have column Name
'Noida' 'Delhi' 'Lahor' 'Bagdad' 'New York' 'Bangkok' 'Londan' 'Dubai' 'Islamabad' 'Columbo'
through Group_concat i want that all city name come in alphabetically order in different rows as like given below
'Bagdad,Bangkok' 'Columbo' 'Delhi,Dubai' 'Islamabad' 'Lahor,Londan' 'New York,Noida'
Your are looking for the order by
clause in group_concat()
along with aggregation by the first letter in the string:
select group_concat(name order by name)
from cities
group by left(name, 1)
order by left(name, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With