i’ve a table
---------
| NAME |
|---------|
| arun |
| balu |
| sunny |
| binu |
| binoy |
| cinny |
| aiju |
| dolly |
---------
i’ve wrote a query to get sorted list in mysql
SELECT name FROM students ORDER BY name ASC
and i got it all names sorted but i don’t know how to get the output as shown below
---------
| NAME |
|---------|
| A |
| aiju |
| arun |
| B |
| balu |
| binoy |
| binu |
| C |
| cinny |
| D |
| dolly |
| S |
| sunny |
---------
can anyone please tell me how to get this output?
If you want to perform this in SQL, then you could use a
UNION ALLquery. The first query will return thenameand the second query will return the first letter of each name. Then you canORDER BYthe result:See SQL Fiddle with Demo
The result is: