lets say there is one table called 'phone_book' have columns name and contact_no. How to write a SQL query to display only first row from each alphabet from the column 'name' ?
Asked
Active
Viewed 521 times
0
-
First, choose the database you are using. I removed the incompatible database tags. – Gordon Linoff Mar 09 '17 at 11:44
-
1Possible duplicate of [group by first character](http://stackoverflow.com/questions/666525/group-by-first-character) – Ham3d Mar 09 '17 at 11:46
1 Answers
0
You can use query like this,
Select Top 1 * from phone_book where name like 'A%'
UNION
Select Top 1 * from phone_book where name like 'B%'
UNION
Select Top 1 * from phone_book where name like 'c%'
UNION
Select Top 1 * from phone_book where name like 'D%'
.
.
.
.
.
Select Top 1 * from phone_book where name like 'Y%'
UNION
Select Top 1 * from phone_book where name like 'Z%'

Arun D
- 444
- 3
- 7
- 23