I have an LINK field in my table. Some rows have a link, some don't.
I'd like to select all rows where LINK is present. (length is greater than X characters).
How do I write this?
SELECT * FROM sometable WHERE CHAR_LENGTH(LINK) > 1
Here's the MySql string functions page (5.0).
Note that I chose
CHAR_LENGTH instead of
LENGTH, as if there are multibyte characters in the data you're probably really interested in how many characters there are, not how many bytes of storage they take. So for the above, a row where LINK is a single two-byte character wouldn't be returned - whereas it would when using
Note that if
NULL, the result of
CHAR_LENGTH(LINK) will be
NULL as well, so the row won't match.