Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite reverse LIKE wildcard in database

Tags:

sqlite

Take this table.

 id  |  sentence
 -------------------
 2   |  I % cake.
 3   |  My name is %

You will notice the wildcards are actually in the fields within the database.

With MySQL you can do this :

SELECT id FROM mytable WHERE sentence LIKE 'My name is John';

In this example this would return 3.

So it's like a regular LIKE but in reverse.

My question is can this be done any way in SQLite, because when I try it I get no results. Is there a way to implement it perhaps if not ?

EDIT: Sorry was getting my LIKE & MATCH mixed up. Corrected it.

like image 886
Rog Avatar asked Aug 29 '26 07:08

Rog


1 Answers

sqlite doesn't support a so-called "reverse LIKE" operator (nor does MySQL, for that matter), but it does support what we might call a "reverse reverse LIKE" operator. Try this:

SELECT id FROM mytable WHERE 'My name is John' LIKE sentence;
like image 193
pilcrow Avatar answered Aug 31 '26 17:08

pilcrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!