+4 votes
in Databases by (6.8k points)
In my table, one VARCHAR column has strings of different sizes. How can I find the value that has the maximum length?

1 Answer

0 votes
by (27.1k points)

I have a table "videodb" and the column "title" is VARCHAR.

I can get the title with maximum length using one of the following SQLs.

Approach 1

SELECT  title, LENGTH(title) AS title_len
FROM    videodb
ORDER BY  title_len DESC LIMIT 1

Approach 2

SELECT  max(LENGTH(title)) AS title_len
FROM    videodb