php - select three values based on the group by of alphabets a-z -
i have table named 'user' has fields named 'id','name'.
i need select 3 names each alphabet , display page, total results 26*3 = 78.
i have done using php, need optimize query, can done in single query ?
please have seek one:
select alphabet, name ( select left(name, 1) alphabet, name, @num := if(@prev = left(name, 1), @num + 1, 1) row_num, @prev := left(name, 1) previous yourtable, (select @num:=0, @prev:='') v order name ) sq row_num <= 3
php mysql performance
No comments:
Post a Comment