MySQL SELECT statement for field "length" greater than 1

I have a LINK field in my table. Some lines have a link, some do not.

I would like to select all the lines in which LINK is present. (length greater than X characters).

How do I write this?

+41
mysql
09 Oct '09 at 18:51
source share
4 answers

What about:

SELECT * FROM sometable WHERE CHAR_LENGTH(LINK) > 1 

Here is the MySql (5.0) line functions page .

Note that instead of LENGTH I chose CHAR_LENGTH , as if the data that you are probably really interested in is how many characters there are, and not how many bytes of memory that they accept, there are multibyte characters. Thus, for the above, a string in which LINK is the only double-byte character will not be returned, whereas when using LENGTH .

Note that if LINK is NULL , the result of CHAR_LENGTH(LINK) will also be NULL , so the string will not match.

+83
Oct 09 '09 at 18:54
source share
 select * from [tbl] where [link] is not null and len([link]) > 1 

For MySQL user:

 LENGTH([link]) > 1 
+11
Oct 09 '09 at 18:53
source share

Just in case, someone wants to find, as in an oracle, and came here (like me), the syntax

 select length(FIELD) from TABLE 

just in case;)

+5
Jul 26 '15 at 6:16
source share

Try:

 SELECT * FROM YourTable WHERE CHAR_LENGTH(Link) > x 
+4
Oct 9 '09 at 18:54
source share



All Articles