tags:

views:

82

answers:

3

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 to write this?

A: 
select * from [tbl] where [link] is not null and len([link]) > 1
yodaj007
The `[identifier]` syntax is used only by MS SQL -- SQL Server and Access (as far as I know). This question is about MySQL.
dcrosta
I don't think len() is a valid MySql function
ChssPly76
Oh, yeah, I completely missed that part of the question. Should I delete this answer, as it's not at all relevant?
yodaj007
+4  A: 

How about:

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 LENGTH.

Note that if LINK is NULL, the result of CHAR_LENGTH(LINK) will be NULL as well, so the row won't match.

Jon Skeet
+1  A: 

try:

SELECT
    *
    FROM YourTable
    WHERE CHAR_LENGTH(Link)>x
KM