ellie
ellie

Reputation: 23

Using the like statement in MYSQL without the order mattering

Is there a way to use the like statement in MYSQL without the order mattering? For example:

WHERE Country LIKE '%land1%land2%';

and

WHERE Country LIKE '%land2%land1%';

are two completely different statements. While the first one only gets data from rows that contains the words land1, and land2 in that specific order, the second one only gets data from rows that contains the words land2, and land1 in that specific order. Is there a way to bypass this?

Upvotes: 1

Views: 418

Answers (3)

Al Amin Chayan
Al Amin Chayan

Reputation: 2500

WHERE Country REGEXP 'land1|land2';

Which will be output as same as:

WHERE (Country LIKE '%land1%' OR Country LIKE '%land2%');

Upvotes: 0

Isaac
Isaac

Reputation: 11805

Example using Regexp

WHERE Country REGEXP '.*(land[12]){2}.*';

Upvotes: 1

David L
David L

Reputation: 33883

Use an AND boolean operator with two independent LIKE clauses.

WHERE Country LIKE '%land2' AND Country LIKE '%land1%';

Upvotes: 2

Related Questions