I have a query which gets all records ordered by last_name. Now I would like to create a loop that groups these results by the first letter of the last name and display the
in your query, try adding something like:
group by substr(last_name,1,1)
i.e.
select substr(last_name,1,1) as alpha, * from tableName group by substr(last_name,1,1)