Learning SQL. Have a simple table games with field title. I want to search based on title. If I have a game called Age of Empires III: Dynasties
, and I use LIKE
with parameter Age of Empires III: Dynasties
, everything works fine, the search returns the record with that name. But if I search with Age of Empires III
, it doesn't return any records:
SELECT * from games WHERE (lower(title) LIKE 'age of empires III');
This doesn't return anything. Should I be using something else instead of LIKE
?
I am using MySQL.
This question is related to
sql
Aside from using %
, age of empires III
to lower case is age of empires iii
so your query should be:
select *
from games
where lower(title) like 'age of empires iii%'
COLLATE UTF8_GENERAL_CI
will work as ignore-case.
USE:
SELECT * from games WHERE title COLLATE UTF8_GENERAL_CI LIKE 'age of empires III%';
or
SELECT * from games WHERE LOWER(title) LIKE 'age of empires III%';
You need to use the wildcard % :
SELECT * from games WHERE (lower(title) LIKE 'age of empires III%');
Source: Stackoverflow.com