Si Pot
Si Pot

Reputation: 33

MySQL: SELECT Like and char_length

I'm trying to make a query, something like this: SELECT * FROM table WHERE field_name LIKE "keyword%" AND CHAR_LENGTH("keyword%")<20. I know this one is wrong and it's not working, but what's the right way to get the right results?

Thank you!

Upvotes: 3

Views: 5492

Answers (2)

Alex LE
Alex LE

Reputation: 20572

CHAR_LENGTH should be used with field_name not the like pattern: "keyword%"

SELECT * FROM table WHERE field_name LIKE "keyword%" AND CHAR_LENGTH(field_name)<20

Upvotes: 0

Adriaan Stander
Adriaan Stander

Reputation: 166576

Why not try

SELECT  * 
FROM    table 
WHERE   field_name LIKE "keyword%" 
AND     CHAR_LENGTH(field_name)<20

Upvotes: 5

Related Questions