Jump to content

Find values that start with a user defined letter


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!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.