1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

mysql get first letter of a column from a table

Let’s say you have a store table in your database and you want to get the first letter of each store’s name. So you can create a menu by first letter of each store name and not having a letter that contains no stores.

$stores = $this->Store->find('all',array(    'order'=>'name ASC',
'fields'=>'DISTINCT(UPPER(LEFT(name,1))) AS letter',
'conditions'=>array("UPPER(LEFT(name,1)) REGEXP '[A-Z]'")));
Share:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Twitter
  • Yahoo! Bookmarks
Share your opinion! Post your thoughts.