I have a SQLite database with a table named minecraft
.
+----+----------------------+
| id | name |
+----+----------------------+
| 1 | Pocket Mine MP |
| 2 | Open Computers |
| 3 | hubot minecraft skin |
| 4 | Terasology |
| 5 | msm |
+----+----------------------+
I need to find all the records which have 'e' and 'o' in their 'name' field. Here is my Select query:
select * from minecraft where name like '%e%o%'
Here is the result of the above query:
+----+----------------+
| id | name |
+----+----------------+
| 2 | Open Computers |
| 4 | Terasology |
+----+----------------+
The problem is that the Like predicate matches the entire value, not words. The row with id = 2 should not be matched, because all the criteria didn't happen in a single word ('e' is found in the first word and 'o' in the other word): Open Computers.
How should I change my Select query so it matches the only row with 'e' and 'o' in a single word?
+----+------------+
| id | name |
+----+------------+
| 4 | Terasology |
+----+------------+
Thanks
LIKE
is not strong enough for this, but you could use REGEXP instead. It seems from the documentation that you have to supply the function yourself, but you will probably be able to find one - some details are in this answerLIKE
you showed cannot use index too (only prefix matches can).'Open'
and'Computers'
haveo
ande
. Unless you only want lowero
(and excludeO
) and you want the order to be "first-e-then-o" in the same word (and exclude "first-o-then-e")