S.M_Emamian
S.M_Emamian

Reputation: 17393

How to check if a string contains a substring - mysql

In my table I have a column that contains a random values. They have a regular structure like below :

id    | value
----------------  
1 | 1_426_7894(245)
2 | 4_463_9654(465)
3 | 3_954_3678(465)
4 | 9_356_5412(157)
5 | 5_986_3578(987)
6 | 2_125_4689(749)
7 | 8_286_7859(879)

value1_value2_value3(value4)

now,I would like to search in this table where value3 is 3678. Is it possible to make this query ? or PHP should help me ?

Upvotes: 0

Views: 2180

Answers (4)

seahawk
seahawk

Reputation: 1912

Search table where value3 is 3678

select * from
table_name
where INSTR(value,concat("_",3678,"(")>0;

Upvotes: 0

sbouaked
sbouaked

Reputation: 980

Maybe you can do something like that ?

DECLARE @variable varchar(max)
SET @variable = '3678'
SELECT * FROM <table> WHERE variable1 like '%_' + '%_'+ @variable + '(%)'

Upvotes: 0

splash58
splash58

Reputation: 26153

select * from thetable where mid(value, 7, 4) = 3678

Upvotes: 3

Pavlin
Pavlin

Reputation: 5528

use WHERE field LIKE %_value3. The % matches anything.

Upvotes: 0

Related Questions