I have a table that looks like this:
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(30) | NO | | | |
+-------+------------------+------+-----+---------+----------------+
Pretty simple table.
I’m trying to find a way to only select results with a maximum length of 8 characters for a couple of reasons:
1) The HTML table that was created for the record set is too narrow to work with anything greater than 8 characters.
2) We can’t have the names truncated when displaying them.
I was looking through the MySQL manual and can’t find any solid results. I’m going to try using char_length in the where clause and see what I can come up with and will post back what I find, but I’m hoping somebody has done this before.
You need to use
CHAR_LENGTHto get the length of the characters. Try:Additional Info:
LENGTH()returns the length of the string measured in bytes.CHAR_LENGTH()returns the length of the string measured in characters.