Jump to content

Find values that start with a user defined letter


zebe

Recommended Posts

Hi,

I was wondering how you would write a query that would only contain the values of a defined field which start with a defined letter. I have a last name field and I want the user to have the option to display only the last names that start with a letter they specify. EX: Find last names that start with A,B... etc.

Thanks for the help!
Not sure if I follow.

My initial query is as follows:

[code]$sql = "SELECT id, sid, last, first FROM student_data_gen WHERE semester = '$semester' ORDER BY last";
[/code]

What I want to do is find the students by semester but also find only the last names that begin with the user defined letter like, A, B etc.

How would I use LEFT(last, 1) component in the previous code? Again, thanks for all your help!
[!--quoteo(post=338585:date=Jan 20 2006, 07:36 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 20 2006, 07:36 PM) [snapback]338585[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Then add a "WHERE LEFT(last,1)='<your letter here>'" to your query.
[/quote]

Works great, thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.