Hi Jim, I think that you'll find that ' ' is treated as a NULL and as such will always return zero. You are no catering for multiple spaces in the column race_winner. If you were using Oracle, their INSTR function has an optional argument that allows you to search backwards from the end of a string, but you're not, so my guess is that you'll have to extract the results into an array, manipulate the race_winner column, sort the array, then do whatever is coming next. I'm not a MySql expert, just putting in my two bob's worth. Don't forget to LTRIM(RTRIM(race_winner)). Cheers, --- Em seg, 4/4/11, Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx> escreveu: De: Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx> Assunto: Last Name extraction in query Para: php-general@xxxxxxxxxxxxx Data: Segunda-feira, 4 de Abril de 2011, 12:50 having a problem posting this message - forgive any duplication please. Hi, I'm trying to use sql to extract the last name from a person's name field in my table. Here's my Select: $q = "SELECT race_winner,count(race_date) as wins, substr(race_winner,FIELD(' ',race_winner)) as last_name etc.,,, My result keeps coming up with a 0 for the FIELD portion I assume since my output shows a blank last_name. From the docs I believe it should be giving me the right-most portion of the 'race_winner' field beginning where the first space char is found. Am I not using this correctly? Is there a better way to do this? I'm trying to have my results sorted by last name and since the table was not built with separate first/last name fields, I'm stuck with figuring somethign out. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php