Kunwarbir S.
Kunwarbir S.

Reputation: 281

PHP MySQL WHERE Clause with condition

MySQL Table video

id | path
4  | 89_1232
6  | 90_2121

I need to match path before underscore _. For instance 89 , 90. Is it possible with MySQL query.

Right now what I am doing is, fetching all rows and then explode path row:

"SELECT `path` FROM `video`

then foreach () { explode and check }

Upvotes: 1

Views: 41

Answers (1)

Ben
Ben

Reputation: 9001

Use LIKE with wildcards

Example:

SELECT `path` FROM `video` WHERE `path` LIKE '89\_%' ESCAPE '\'

which will search for rows with the pattern 89_{anything}, using the backslash \ as the escape character (to make sure the underscore _ is literal)

Upvotes: 3

Related Questions