Archive for October, 2010

Selecting random value in MySQL

Oct 28 2010 Published by under MySQL

SELECT FLOOR(1 + (RAND() * 100))

where 100 is a maximum allowed number in random sequence

Comments Off

Update timestamp in MySQL datetime field

Oct 13 2010 Published by under MySQL

This example will update a year in table field which was wrongly set to 2011 and set it to 2010.

e.g. 2011-09-20 will be changed to 2010-09-20 throughout the table.

UPDATE $table \
SET $field = $field - INTERVAL 1 YEAR \
WHERE year($field)=2011;

Comments Off

Performance Optimization WordPress Plugins by W3 EDGE