|
1 registered members (Rustydog),
286
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
Forums69
Topics113,635
Posts1,341,406
Members1,814
|
Most Online731 Jan 14th, 2020
|
|
|
SQL question
#1547962
28/08/2015 14:11
28/08/2015 14:11
|
elder81
Unregistered
|
elder81
Unregistered
|
Hello all,
I am doing some work on a customer database and need to delete specific date from a back up table. The data needs to be the top 10 based or date order. (Don't ask why :))
The following script does not work, but what could i use?
delete (select top 10 * from back_notifmsgqueue order by timetosend desc) from back_notifmsgqueue
|
|
|
Re: SQL question
[Re: ]
#1547965
28/08/2015 14:28
28/08/2015 14:28
|
Joined: May 2011
Posts: 2,388 Caston, Norfolk
Blueboyracer
Competition Level
|
Competition Level
Joined: May 2011
Posts: 2,388
Caston, Norfolk
|
If you mean delete the previous 10 days data from today in a table then the following would be do it...
delete from back_notifmsgqueue where timetosend >= date_sub(curdate(), interval 10 day)
However, if you mean that you want to delete the most recent 10 days in a table and it has not been updated for a period of time then you will have to perform a subquery based upon your max(timetosend) to achieve the same
Last edited by Blueboyracer; 28/08/2015 14:29.
|
|
|
Re: SQL question
[Re: ]
#1547970
28/08/2015 15:24
28/08/2015 15:24
|
elder81
Unregistered
|
elder81
Unregistered
|
Thats what I was trying to acheive in other examples, but without the IN.
Thanks StuP
|
|
|
Re: SQL question
[Re: ]
#1547975
28/08/2015 15:52
28/08/2015 15:52
|
Joined: Dec 2005
Posts: 12,295 Sandhurst
Begbie
Ex El Presidente
|
Ex El Presidente
I AM a Coop
Joined: Dec 2005
Posts: 12,295
Sandhurst
|
Please use 'Begin Tran' before you do the delete, as I've just had to restore a 160GB DB back for a client because they did they a delete statement before checking what it would actually delete.
Your car is Usain Bolt with wellies
|
|
|
Re: SQL question
[Re: Begbie]
#1549797
17/09/2015 22:20
17/09/2015 22:20
|
Joined: Dec 2014
Posts: 420 uk
OnlyItalian
Enjoying the ride
|
Enjoying the ride
Joined: Dec 2014
Posts: 420
uk
|
Please use 'Begin Tran' before you do the delete, as I've just had to restore a 160GB DB back for a client because they did they a delete statement before checking what it would actually delete. That is properly good advice. Don't commit the transaction until you're sure the query does what you want. Same goes for insert and update statements really. And for added safety and if the db is offline then take a backup before doing anything.
Last edited by OnlyItalian; 17/09/2015 22:20.
"Proud owner of LE141 and a 99 VIS broomie "
|
|
|
|
|
|