Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i search from serialize field in mysql database?

How do i search from serialize field in mysql database except mysql like statement?

The data is:

a:9:{s:2:"m1";s:4:"1217";s:2:"m2";s:8:"9986-961";s:2:"m3";s:19:"1988-03-07 00:00:00";s:2:"m4";s:0:"";s:2:"m5";s:0:"";s:2:"m6";s:0:"";s:2:"m7";s:3:"104";s:2:"m8";s:6:"150000";s :2:"m9";s:18:"Ok Then, Yes It Is";}

I need the row in which the m9 value is 'Yes It Is'. I do not want to use mysql 'like' statement.

I have tried:

SELECT * FROM table WHERE field like '%Yes It Is%'

Can you please help.

like image 473
Sourav Basak Avatar asked Jul 01 '14 10:07

Sourav Basak


1 Answers

Have you tried the following:

SELECT * FROM table WHERE field like '%"m9";s:18:"Ok Then, Yes It Is";%'

?

But in fact if you want to search in such data, you should simple create proper structure of your table and not to put all serialized data in one column

like image 133
Marcin Nabiałek Avatar answered Sep 25 '22 15:09

Marcin Nabiałek