How to use MySQL to search in PHP serialized fields

Well, first rule – you should not do this. But if there is good reason, consider using such query for searching in index-based arrays:

SELECT * FROM table WHERE your_field_here REGEXP '.*;s:[0-9]+:"your_value_here".*'

In case you have assoc array serialized you can use:

SELECT * FROM table WHERE your_field_here REGEXP '.*"array_key_here";s:[0-9]+:"your_value_here".*'

Of course it won’t be very fast but in small tables should be enough

Source:
http://www.blastar.biz/2013/11/28/how-to-use-mysql-to-search-in-php-serialized-fields/

MySQL: Select records from today, this week and this month

MySQL Logo

Assuming your date column is an actual MySQL date column:

SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY score DESC;        
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 WEEK) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY score DESC;

Source: http://stackoverflow.com/a/5293226/1794834

Pin It on Pinterest