AlanBE
AlanBE

Reputation: 133

MySQL search for exact match

I would like to search for exact match in SQL:

In searchString column in user table, I have :

[email protected] 654433 active other text
[email protected] 43434 inactive other text

I would like to search for active or inactive only:

SELECT u FROM User u WHERE u.searchString = 'active'

or

SELECT u FROM User u WHERE u.searchString = 'inactive'

But it returns both the 2 rows for either of statements.

Expected result:

searchString = 'active' to return [email protected] row only

searchString = 'inactive' to return [email protected] row only

Please help. Thanks.

Upvotes: 0

Views: 48

Answers (1)

Fahmi
Fahmi

Reputation: 37473

use like operator with OR condition

SELECT u FROM User u WHERE u.searchString like '%active%' 
   or u.searchString like '%inactive%'

Upvotes: 1

Related Questions