How to MySQL query -


i have 16k rows table columns

id, author_name, letter; (where letter first letter first name)

i want make sql query list authors in groups of 3 each letter a-z

like:

a

albert, ana, antony,

b

ben, boston, bell,
how can write query ? thank you.

try this, :

set @counter =0, @letter:='';   select *  (select @counter:=if(letter=@letter, @counter+1,1) counter, @letter = letter,  author table order letter, author) t  counter<=3 order letter, name 

it works on comparing previous value , restarting numbering when letter changes else incrementing.


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -