Delete from MySQL + select affected
-
Hi! I am trying to create a statement, that deletes rows where UpdateDate is older than 7 day and than selects that rows for me. I need to get those rows back to my application to write the log file. In 2 steps (select and than delete by ID) is no problem. But is there a way to do this in one single step? What I need to get back is table.ID, table.CreationDate, table.Name ... It is nearly the complete row. THX for your help!
-
Hi! I am trying to create a statement, that deletes rows where UpdateDate is older than 7 day and than selects that rows for me. I need to get those rows back to my application to write the log file. In 2 steps (select and than delete by ID) is no problem. But is there a way to do this in one single step? What I need to get back is table.ID, table.CreationDate, table.Name ... It is nearly the complete row. THX for your help!
Member 9935038 wrote:
But is there a way to do this in one single step?
What do you mean with "single step"? If you need them to be a single operation then it'd be wrapped in a transaction. That'd mean that there'd be two more extra statements. If you're wondering if there's a command that does both a select and a delete, then the answer is no, but if you need that you can wrap 'em both in a stored procedure.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Hi! I am trying to create a statement, that deletes rows where UpdateDate is older than 7 day and than selects that rows for me. I need to get those rows back to my application to write the log file. In 2 steps (select and than delete by ID) is no problem. But is there a way to do this in one single step? What I need to get back is table.ID, table.CreationDate, table.Name ... It is nearly the complete row. THX for your help!
I imagine MySql has temp tables like Microsoft Sql does. You can insert the values you want to log into a temp table and then delete the records and then select from your temp table at the end.
There are only 10 types of people in the world, those who understand binary and those who don't.