Re: Deleting, skip the first n records

2006-10-05 Thread DuĊĦan Pavlica
__ -- Original Message -- FROM: Brian Dunning [EMAIL PROTECTED] TO:mysql@lists.mysql.com DATE: Wed, 4 Oct 2006 08:49:48 -0700 SUBJECT: Re: Deleting, skip the first n records The offset is what I was thinking

Deleting, skip the first n records

2006-10-04 Thread Brian Dunning
I'm trying to delete all but the newest n records. DELETE FROM tablename ORDER BY creation DESC LIMIT=n This does the opposite of what I want. Is there some way to tell it to start the delete after n and delete all the remaining records? -- MySQL General Mailing List For list archives:

Re: Deleting, skip the first n records

2006-10-04 Thread Dan Julson
You can add an offset in the Limit statement. Look at the Select Syntax in the docs. There is an even simpler solution to this problem. Use your creation field within a Where clause instead of using Order by and Limit. -Dan I'm trying to delete all but the newest n records. DELETE

Re: Deleting, skip the first n records

2006-10-04 Thread Dan Buettner
Brian, assuming you have an identity column of some kind (we'll call it id here), this should work: CREATE TABLE tmptable (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY); INSERT INTO tmptable (id) SELECT id FROM tablename ORDER BY creation DESC LIMIT 1; DELETE FROM tablename WHERE id NOT IN

Re: Deleting, skip the first n records

2006-10-04 Thread Brian Dunning
The offset is what I was thinking of - that would be the simplest - but as far as I can tell, delete doesn't support the offset. It's not documented, and it gives me an error when I try it. I was hoping to avoid two queries but it sounds like that's what I might have to do. On Oct 4,

re[2]: Deleting, skip the first n records

2006-10-04 Thread Rob Desbois
__ -- Original Message -- FROM: Brian Dunning [EMAIL PROTECTED] TO:mysql@lists.mysql.com DATE: Wed, 4 Oct 2006 08:49:48 -0700 SUBJECT: Re: Deleting, skip the first n records The offset is what I was thinking

Re: re[2]: Deleting, skip the first n records

2006-10-04 Thread Brian Dunning
__ -- Original Message -- FROM: Brian Dunning [EMAIL PROTECTED] TO:mysql@lists.mysql.com DATE: Wed, 4 Oct 2006 08:49:48 -0700 SUBJECT: Re: Deleting, skip the first n records The offset is what I was thinking of - that would be the simplest

Re: Deleting, skip the first n records

2006-10-04 Thread Dan Julson
__ -- Original Message -- FROM: Brian Dunning [EMAIL PROTECTED] TO:mysql@lists.mysql.com DATE: Wed, 4 Oct 2006 08:49:48 -0700 SUBJECT: Re: Deleting, skip the first n records The offset is what I was thinking