Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Jverg on
I have a table with 2.000.000 rows. These rows have a timestamp column and i want to delete all the values except 100 rows with the biggest timestamp. Any ideas on how to do this thing?? I will be very gratefull for your help..
Comments
This is not Drupal specific,
This is not Drupal specific, but you can simply delete rows with a condition.
db_delete('my_table')->condition('timestamp', 12345678, '>')->execute();
What's new and changing in PHP 8
i need
i need something like this :
Take a backup before you
Take a backup before you execute this:
Note that this should leave the most recent 100 timestamp in the table, which is what I understood from your original post.
yes it is but
Yes it is what i really want to achieve but your code do not work for me and i dot know why
Probably because your table
Probably because your table isn't named table1.
i put my name
i put the name of my table and not table1
Probably something else in
Probably something else in your code then.
here is . . .
Try this:
Try this:
nothing
:( :( :( :(
How are you executing this
How are you executing this code? In what function? Are you sure it's even being executed?
i have a function with that code
i have a function with that code and i call this function on cron run and when cron is running i am having also these values.
What does $timestamp equal
What does $timestamp equal here:
Nothing again
These lines of code also do not do nothing... Maybe if we use something like "rowCount" ?
if i use
If i use these lines of code it works perfect and deletes all the values that have timestamp > 1423662475