Mohammad Noori
Mohammad Noori

Reputation: 147

How to get rows by a string field that not in a string?

I have a table like this:

Id Name

1 Test1

2 Test2

3 Test3

And I have a string like 'Test1Test2' So I want records that Name not in that string like Test3. How can I get this row in sqlite?

Upvotes: 1

Views: 40

Answers (1)

MikeT
MikeT

Reputation: 57103

You can use either the instr core function e.g.

SELECT * FROM thetable WHERE instr('Test1Test2',name) < 1;

instr(X,Y)

Or you could use LIKE e.g.

SELECT * FROM thetable WHERE NOT ('Test1Test2' LIKE '%'||name||'%');

The LIKE, GLOB, REGEXP, and MATCH operators

Upvotes: 1

Related Questions