Choletski
Choletski

Reputation: 7515

SQLite select rows containing whole word

I need to select rows that contains a whole word, NOT a substring. For example from these rows:

I need to get only first one (that contains word good), but with my sql query I get both of them.

select *
from my_tab
where my_column like '%good%'

Please note, I need this in sqlite, where not all usual sql functions are available.

Upvotes: 0

Views: 1376

Answers (3)

skamradt
skamradt

Reputation: 15538

You can also use regular expressions (see https://antonz.org/sqlean-regexp/) to add additional parsing to the beginning and end of the substring your searching for, although it will add complexity and does require adding a module to the SQLite engine. One potential repository that includes the regular expression function is https://github.com/nalgeon/sqlean

Upvotes: 0

Ullas
Ullas

Reputation: 11556

You can check it like a space between both % symbols and a and % int end of the word and a % and to the beginning of the word which you need to search.

Query

select * from your_table_name
where words like '% good %'
or words like 'good %'
or words like '% good';

Upvotes: 5

Serg
Serg

Reputation: 22811

Try

select * 
from table
where ' '||words||' ' like '% good %'

Upvotes: 0

Related Questions