# MYSQL / PHP query to return alphabetical listing

**URL:** https://forum.kirupa.com/t/mysql-php-query-to-return-alphabetical-listing/302863
**Category:** programming
**Created:** [January 8, 2010, 9:48pm UTC](https://forum.kirupa.com/t/mysql-php-query-to-return-alphabetical-listing/302863 "2010-01-08T21:48:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![natronp](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@natronp](https://forum.kirupa.com/u/natronp)
#### Post date: [January 8, 2010, 9:48pm UTC](https://forum.kirupa.com/t/mysql-php-query-to-return-alphabetical-listing/302863/1 "2010-01-08T21:48:17Z")

</div>

trying to return a recordset where the first letter of a field value is a predetermined letter of the alphabet:

```auto
$data = mysql_query("SELECT * FROM physicians WHERE Left(lastName, 1) = '$sv' 

```

This almost seems to work but is buggy. I have database records where ‘lastName’ starts with an ‘s’, but will not show up if I throw ‘s’ or ‘S’ at this query as the value of the $sv variable.

If I re-enter that record in the database, i may or may not get that record to show up when i pass “s”.

The records are in there because if I run a different query on a different field, they show up…

I’m sure there’s more to returning query results alphabetically that i’m missing… can anyone help?

My field type is varchar if that helps…
