TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-23-2009, 07:25 PM   #1 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default MySQL doesn't support LIMIT subquery...

Without realizing that MySQL doesn't yet support the following syntax, I wrote the following query (simplified here with data already generated) to perform a delete;

Code:
DELETE FROM `wp_1_statpress` WHERE SUBSTR(timestamp, 1, 10) <> '2009-10-23' AND id NOT IN (SELECT id FROM `wp_1_statpress` WHERE SUBSTR(timestamp, 1, 10) = '2009-10-22' LIMIT 30)
Which returns error #1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

So I attempted to rewrite the query using an inner join, but I'm getting an error in my syntax that I can't seem to deduce just yet;

Code:
DELETE FROM  `wp_1_statpress` AS physical INNER JOIN (SELECT id FROM `wp_1_statpress` WHERE SUBSTR(timestamp, 1, 10) = '2009-10-22' LIMIT 30) AS virtual ON physical.id = virtual.id WHERE SUBSTR(timestamp, 1, 10) <> '2009-10-23'
Can somebody spot my error? I'd like to perform this operation without having to pull the rows and re-insert them later if I can. That would be a plain pain in the arse.
delayedinsanity is offline  
Reply With Quote
Old 10-23-2009, 07:49 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Temporary tables are Snazzy. I bypassed having to code any extra PHP to do this by using straight SQL;

Code:
CREATE TEMPORARY TABLE old_data SELECT * FROM `wp_1_statpress` WHERE SUBSTR(timestamp, 1, 10) = '2009-10-22' LIMIT 30
DELETE FROM `wp_1_statpress` WHERE SUBSTR(timestamp, 1, 10) <> '2009-10-23'
INSERT INTO `wp_1_statpress` SELECT * FROM `old_data`
This seems to be a pretty speedy way of getting what I wanted done, but nevertheless if I could perform it one query, I would prefer to do so. So while the problem is resolved for all intensive purposes, if anybody can see what's wrong with my original query I'd still be interested.
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Replication support in Zend Framework Orc General 4 02-19-2013 04:26 AM
Securing your MySQL Queries with Sprintf Wildhoney General 26 03-18-2008 06:52 PM
MySQL Sell Up Alan @ CIT The Lounge 12 01-17-2008 05:46 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM
Notepage like application to open large MySQL files Wildhoney General 6 12-07-2007 02:18 PM


All times are GMT. The time now is 04:03 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design