views:

128

answers:

2

Hi guys!

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!

+1  A: 

Why not try

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

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
Alex LE