Forum Moderators: coopster
Is there any way to select a MySQL row by the length of a string?
For example, let's say I have a table with three fields : ID, Name, and Comment. Essentially what I want to do is select rows where the length of Comment is greater than 50 characters.
How do I go about doing this?
I think you would have to store the string length of "comment" in a separate field.
Another way is to select all comments and use PHP to look for the string length of every comment. But of course that is ad hoc and less efficient.
Another solution I came up with upon reading your response was to create another field in the table for comment length, and stick the result of strlen($comment) in the comment field length.
However, selecting by length is a solution I only want to use temporarily. Is there a way where all I have to do is edit the query?
SELECT * FROM tablename WHERE LENGTH(comment)>50;
?
Perhaps you want to check out: MySQL Manual: String Functions: LENGTH() [mysql.com]
SN
So uh... spare the sarcasm.
It takes a lot more getting used to than the php.net site but I would say that the php.net site is the best site I have ever seen for a language. Once you get used to the mysql site it works quite well. It just isn't overly forgiving for people trying to learn sql. If you know roughly what you are looking for it is usually a click or two away.