Re: MySQL alphabetical listing
| From: | Paul DuBois | Date: | Tue, 18 Sep 2001 21:47:13 +0000 |
| Subject: | Re: MySQL alphabetical listing | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-12556@lists.php.net to get a copy of this message | ||
At 2:37 PM -0700 9/18/01, Photocon wrote:
Heya all... I have a listing of last names in a table. I would like to get MySQL to give me a result set of last names that began with a letter so that in PHP I can put them into alpha order. I don't want a set of all names, just those with one letter (the idea being I can then have one letter per page), and I don't want to "select all" from the whole table. Does anyone know how to do this, or am I going about it the wrong way? Thanks --Photocon Conrad Hunziker III www.nightskyent.comWhat, you mean like: SELECT last_name FROM tbl_name WHERE LEFT(last_name,1) = 'A' or something? If so, you don't need to have PHP put them in order. Just add ORDER BY last_name to the query. If you want to know which letters last names begin with in your table (so that you can, for example, avoid generating a page for 'X' if no names begin with that letter), do this: SELECT DISTINCT LEFT(last_name,1) AS letter FROM tbl_name ORDER BY letter -- Paul DuBois, paul@snake.net