Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select distinct first character based on the string column

In SQLite I have a table of contacts with one of the columns being last_name. How can I get unique set of first characters of all last names in the table? Something like ['a', 'b', 'd', 'f', 'w']. It would help if query would be case insensitive. I'm using SQLite on Android. Thanks

like image 322
Bostone Avatar asked May 03 '26 04:05

Bostone


1 Answers

This might work:

SELECT DISTINCT lower(substr(last_name,1,1)) AS last_initial FROM my_table;
like image 195
Ted Hopp Avatar answered May 05 '26 18:05

Ted Hopp