. . .

MySql query – Grouping by first character in field value

Published: December 15, 2010

MySQL select statement for querying records grouped by first character of value

SELECT case when
       SUBSTRING( UPPER(`title`) from 1 for 1) between '0' and '9' then
       '0-9' else SUBSTRING( UPPER(`title`) from 1 for 1) end  as letter,
  count(title) AS occurences
  FROM `tablename`
  GROUP BY letter
  ORDER BY letter;

 

Result:

letter occurence
0-9 2
A 1
D 4
H 5
M 7
R 2

 

Don't forget to share this post

    Let's Build Digital Excellence Together


    • Cost Efficient Solutions.
    • Minimal Timelines.
    • Effective Communication.
    • High Quality Standards.
    • Lifetime Support.
    • Transparent Execution.
    • 24/7 Availability.
    • Scalable Teams.

    Join Our 200+ Happy Clients Across Globe


    Free Consultation.

      Do you need help in strategy, innovation or growth of your startup/business? Experts from our team will get in touch with you.

      Please do not post jobs/internships inquiries here.