2

I am trying to use the LIKE operator in my query as follows:

mysql> select cat_title from category where cat_title like '%Indian%Restaurant%';
+--------------------+
| cat_title          |
+--------------------+
| Indian_Restaurants |
+--------------------+
1 row in set (2.59 sec)

However, since I want to do a case insensitive search, I am trying:

mysql> select cat_title from category where UPPER(cat_title) like UPPER('%Indian%Restaurant%');
Empty set (2.83 sec)

Why is the second query not working?

steve landiss
  • 1,833
  • 3
  • 19
  • 30

3 Answers3

1

Most likely the collation on the cat_title column is case insensitive. Use

... cat_title LIKE '%Indian%Restaurant%' COLLATE utf8_bin

See also

Community
  • 1
  • 1
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
1

in all the sql there is ILIKE which is responsible to do case insensitive compression, so you can modify your query like below

select cat_title from category where cat_title ilike '%Indian%Restaurant%';
0

Not sure what's your question. The UPPER function won't work before a 'like' operator. If you want a case-insensitive search, use the operator 'like' only, since it's case-insensitive.

On the other hand, if you want a case-sensitive search, you may try using

   cat_title COLLATE Latin1_General_BIN LIKE '%Indian%Restaurant%'
fpcmm
  • 31
  • 7