tommo74 Posted May 17, 2007 Share Posted May 17, 2007 If I've got a table with a column of Surnames, is there any way to select all the surnames that are shorter than 5 letters long. I know I could return ALL the surnames in a result set and go through the result set to check the length of each one individually, but is there a query where I could return just the Surnames shorter than 5 letters ? Quote Link to comment https://forums.phpfreaks.com/topic/51820-solved-selecting-values-of-a-certain-length/ Share on other sites More sharing options...
effigy Posted May 17, 2007 Share Posted May 17, 2007 SELECT field FROM table WHERE LENGTH(field) < 5 Quote Link to comment https://forums.phpfreaks.com/topic/51820-solved-selecting-values-of-a-certain-length/#findComment-255374 Share on other sites More sharing options...
heavencore Posted May 17, 2007 Share Posted May 17, 2007 length() may not be accurate, i think you might mean char_length() ? as mysql points out: A multi-byte character counts as a single character. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5. although length would still work in most cases (as far as i understand it) Quote Link to comment https://forums.phpfreaks.com/topic/51820-solved-selecting-values-of-a-certain-length/#findComment-255376 Share on other sites More sharing options...
tommo74 Posted May 17, 2007 Author Share Posted May 17, 2007 Thats it, length() works fine in my situation, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/51820-solved-selecting-values-of-a-certain-length/#findComment-255417 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.