-2
Table

Id name

1 Akhil

2 Akira

3 Anuj

4 Bia

5 Bina

6 Chetu

7 Chini

8 Chikna

9 Chana


Output

Id name

1 Akhil

2 Akira

3 Bia

4 Bina

6 Chetu

7 Chini

Nik
  • 37
  • 1
  • 4
  • How have you attempted this so far, and where are you failing? If you show your query we can probably help, but StackOverflow questions aren't about simply requesting code to solve your problems. – Guildencrantz Jan 09 '16 at 22:30
  • Possible duplicate of [MySQL Select Query - Get only first 10 characters of a value](http://stackoverflow.com/questions/14959166/mysql-select-query-get-only-first-10-characters-of-a-value) – xAoc Jan 09 '16 at 22:37

1 Answers1

0

Here the Query. In the Result are more field, but you can remove them. They are only to see how the Query works

SELECT * FROM (
  SELECT
    @nr :=  IF(@old_val = SUBSTRING(t.name,1,1),(@nr +1),1) AS nr,
    @old_val:=SUBSTRING(t.name,1,1) AS tmp,
    t.name FROM mytable t,
    (SELECT @nr:=0, @old_val:='') AS TMP
  ORDER BY NAME
) AS result WHERE nr < 3;

Please let me know if it works for you

Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39