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 char_length(col. column_name) as column_name_length, count(*) as columns, count(distinct tab. table_name) as tables from information_schema. tables as tab inner join information_schema.
SQL Server LEN() Function The LEN() function returns the length of a string. Note: Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces at the start of the string is included when calculating the length.
To work out the length of the largest string in a MySQL table, combine the LENGTH() and MAX() functions together like so: SELECT MAX(LENGTH(field_to_query)) FROM table_to_query; where "field_to_query" is the fieldname you want to query and table_to_query is the table.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With