Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
mySQL Delete not working
Old 09-02-2010, 04:41 PM mySQL Delete not working
Extreme Talker

Posts: 173
Trades: 0
Can someone please have a look at these to sql statements. I am getting the following error on the second one which is a copy of the first one other then replacing the select with Delete.

Quote:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN (tbl_module INNER JOIN tbl_material ON tbl_module.module_id = tbl_mat' at line 2
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN (tbl_module INNER JOIN tbl_material ON tbl_module.module_id = tbl_mat' at line 2
Works:
Quote:
SELECT tbl_material.date_stamp, tbl_material.part
FROM tbl_project
INNER JOIN (
tbl_module
INNER JOIN tbl_material ON tbl_module.module_id = tbl_material.module_id
) ON tbl_project.project_id = tbl_module.project_id
WHERE tbl_project.project = '3418499'
AND tbl_material.date_stamp <= DATE_SUB( NOW( ) , INTERVAL 60
MINUTE )
No Work
Quote:
DELETE
FROM tbl_project INNER JOIN (tbl_module INNER JOIN tbl_material ON tbl_module.module_id = tbl_material.module_id) ON tbl_project.project_id = tbl_module.project_id
WHERE tbl_project.project='3418499'
AND tbl_material.date_stamp<=DATE_SUB(NOW(),INTERVAL 60 MINUTE)
DELETE
FROM tbl_project INNER JOIN (tbl_module INNER JOIN tbl_material ON tbl_module.module_id = tbl_material.module_id) ON tbl_project.project_id = tbl_module.project_id
WHERE tbl_project.project='3418499'
AND tbl_material.date_stamp<=DATE_SUB(NOW(),INTERVAL 60 MINUTE)
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-03-2010, 08:46 AM Re: mySQL Delete not working
Extreme Talker

Posts: 173
Trades: 0
What I have detemined is that you can not use JOIN and Delete in the same statement. What you need to do is nest the queries so that each query is executed and the result is passed ot the next query.

Quote:
$sql='DELETE FROM tbl_material WHERE tbl_material.module_id IN('.
'SELECT tbl_module.module_id FROM tbl_module WHERE tbl_module.project_id IN ('.
'SELECT tbl_project.project_id FROM tbl_project INNER JOIN tbl_project_details ON tbl_project.project_id = tbl_project_details.project_id'.
'WHERE project='.$project.' OR network_number='.$project.')'.
')'.
'AND tbl_material.date_stamp<=DATE_SUB(NOW(),INTERVAL 6 MINUTE)';
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 09-03-2010, 09:56 AM Re: mySQL Delete not working
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You can use a multi table delete using JOINs BUT the storage engine needs to be InnoDb

http://dev.mysql.com/doc/refman/5.0/en/delete.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-03-2010, 10:08 PM Re: mySQL Delete not working
Extreme Talker

Posts: 173
Trades: 0
Just checked and all my tables are InnoDb. At one point I actually got an error that made some sense and indicated that I could not use delete files that were connected with the JOIN. Can't remember the wording exactly. Either way, it is working. Thanks for the commentary.
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 09-12-2010, 09:40 PM Re: mySQL Delete not working
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
How common is InnoDB? Just how likely is it to already be configured for you, on the average web-host's server?
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 09-18-2010, 06:23 PM Re: mySQL Delete not working
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's built in to EVERY MySql server, as are several storage engines InnoDb just needs to be set as default storage engine or set by a CREATE TABLESPACE or ALTER TABLESPACE command using the ENGINE directive
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-25-2010, 02:01 AM Re: mySQL Delete not working
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Oh okay... I remember this tripping me out when I ran into it before (with InnoDB)
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mySQL Delete not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19313 seconds with 12 queries