zebe Posted January 20, 2006 Share Posted January 20, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/3235-find-values-that-start-with-a-user-defined-letter/ Share on other sites More sharing options...
fenway Posted January 20, 2006 Share Posted January 20, 2006 You need the following in your WHERE clause:[code]WHERE LEFT(yourColumn,1)[/code]Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/3235-find-values-that-start-with-a-user-defined-letter/#findComment-11027 Share on other sites More sharing options...
zebe Posted January 20, 2006 Author Share Posted January 20, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/3235-find-values-that-start-with-a-user-defined-letter/#findComment-11028 Share on other sites More sharing options...
fenway Posted January 21, 2006 Share Posted January 21, 2006 Then add a "WHERE LEFT(last,1)='<your letter here>'" to your query. Quote Link to comment https://forums.phpfreaks.com/topic/3235-find-values-that-start-with-a-user-defined-letter/#findComment-11030 Share on other sites More sharing options...
zebe Posted January 23, 2006 Author Share Posted January 23, 2006 [!--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! Quote Link to comment https://forums.phpfreaks.com/topic/3235-find-values-that-start-with-a-user-defined-letter/#findComment-11060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.