Is it possible to order sql data rows by the total number of characters?
e.g. SELECT * FROM database ORDER BY data.length()
You can use just simply LENGTH(), but beware, because it counts the byte number (which won't give you the expected result with multibyte strings). See Alex Reitborts answer below if you're looking for MS SQL Server variant.
Well, you can use the LEN() function to find the length of a String value in SQL Server, for example, LEN(emp_name) will give you the length of values stored in the column emp_name.
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.
You can use SQL length functions in the SELECT statement and other data manipulation statements. Length functions return the length of a column, string, or variable in bytes or characters. For the syntax of these functions, see the Expression segment in the IBM® Informix® Guide to SQL: Syntax .
I think you want to use this: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length
SELECT * FROM table ORDER BY CHAR_LENGTH(field)
You can use just simply LENGTH(), but beware, because it counts the byte number (which won't give you the expected result with multibyte strings).
SELECT * FROM database ORDER BY Len(data)
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