Nov 13, 2019 | MySQL |
Let say you have a table called “my_table” with an auto-increment column called “id” and you want the id column to start counting from 1,2,3,… then use the following SQL queries.
SET @num := 0;
UPDATE my_table SET id = @num := (@num+1);
ALTER TABLE my_table AUTO_INCREMENT =1;
Jan 17, 2015 | MySQL, PHP |
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/
Jan 16, 2015 | MySQL, PHP, Uncategorized |
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
Apr 28, 2013 | MySQL |
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE table1;
TRUNCATE table2;
SET FOREIGN_KEY_CHECKS=1;
Recent Comments