Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match first character only in a field

Status
Not open for further replies.

rmfrance

Programmer
Nov 1, 2001
9
0
0
GB
I'm trying to speed up my site by reducing the number of fields that I need to update in my mysql database.
What I want is a search string that will check the first character in the field so that I can group all "A's", "B's", together, etc...
ie.
Arnold
Amanda
Brett
Craig

... I don't want Craig to be included in the 'A' list because he has an 'A' in his name. He shold be in 'C'. The way I used to do it was have a field named 'Letter' which sorted it. But this is one of the fields I'm trying to avoid.
Please help!!!
 
i don't know if this will work, but try:

group by LEFT(NameField, 1)
 
Hi, you've got to way to do it : extract the 1st char with the mysql SUBSTRING function wich syntax is
SUBSTRING(str FROM pos FOR len)

(visit e. g.
select SUBSTRING('Quadratically',5,6);

you can use also equivalent string functions from your programming language (php and perl provide such functions).
 
piti is somehow right :
SUBSTR can replace LEFT function

select SUBSTR(field_name, 1,1) as first_letter
FROM table_name
group by first_letter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top