Group PHP results on first letter of name

后端 未结 6 1424
粉色の甜心
粉色の甜心 2020-12-10 17:25

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

6条回答
  •  鱼传尺愫
    2020-12-10 17:52

    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)
    

提交回复
热议问题