Jump to content


Photo

Find values that start with a user defined letter


  • Please log in to reply
4 replies to this topic

#1 zebe

zebe
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 20 January 2006 - 06:59 PM

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!

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 January 2006 - 08:23 PM

You need the following in your WHERE clause:

WHERE LEFT(yourColumn,1)

Hope that helps.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 zebe

zebe
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 20 January 2006 - 08:37 PM

Not sure if I follow.

My initial query is as follows:

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

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!

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 January 2006 - 12:36 AM

Then add a "WHERE LEFT(last,1)='<your letter here>'" to your query.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 zebe

zebe
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 23 January 2006 - 03:26 PM

[!--quoteo(post=338585:date=Jan 20 2006, 07:36 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 20 2006, 07:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Then add a "WHERE LEFT(last,1)='<your letter here>'" to your query.
[/quote]

Works great, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users