Gossamer Forum
Home : General : Databases and SQL :

Delete query not working

Quote Reply
Delete query not working
ive got the following sql for my MySQL database using PHP scripting:

DELETE cartcontents.*, sid.sid_sid
FROM sid RIGHT JOIN cartcontents ON sid.sid_sid = cartcontents.carsid
WHERE sid.sid_sid Is Null

I want it to delete records in the table named 'cartcontents' where another record does not exist in the 'sid' table and it doesnt work.
If i replace the 'DELETE' in the above sql, it will display all the correct records that i wish to delete fine without errors, but how do i turn the select query into a delete query? simply replaceing the 'SELECT' with 'DELETE' doesnt work as you can see above, it gives me errors.

The error i get is: 1064-You have an error in your SQL syntax near 'cartcontents.*, sid.sid_sid FROM sid RIGHT JOIN cartcontents ON sid.sid_sid = ca' at line 1

Ive been trying for an hour now to make it work but get the same error, thing is, it will work as a select query no worries, ive eventried it in an access database and the delete query works fine.

Can anyone tell me what im doing wrong?
Quote Reply
Re: [WoSkI] Delete query not working In reply to
You need to go to MySQL.com and read the delete syntax docs.

You can't specify column names in delete queries.

http://www.mysql.com/doc/en/DELETE.html

Last edited by:

Paul: Jan 21, 2003, 5:59 AM
Quote Reply
Re: [Paul] Delete query not working In reply to
i just about memorized that page yesterday trying to do it, but that was no help. And ive taken that field out of it as well and it still dont work, gives same old error.
Ive tried.

DELETE FROM cartcontents.*
sid RIGHT JOIN cartcontents ON sid.sid_sid = cartcontents.carsid
WHERE sid.sid_sid Is Null


DELETE FROM cartcontents
RIGHT JOIN cartcontents ON sid.sid_sid = cartcontents.carsid
WHERE sid.sid_sid Is Null


and a few other combinations, all give the same error. Another thing im thinking of is does MySQL support this type of delete query?

Last edited by:

WoSkI: Jan 21, 2003, 2:02 PM
Quote Reply
Re: [WoSkI] Delete query not working In reply to
The syntax is right there on the page. Notice how deleting from one table is:

DELETE FROM table_name

...and the other two examples use different syntax.

Last edited by:

Paul: Jan 21, 2003, 2:41 PM
Quote Reply
Re: [Paul] Delete query not working In reply to
i gave up and did it another way.
Quote Reply
Re: [WoSkI] Delete query not working In reply to
Did you read that multi table delete's are only supported in mysql 4? Most likely you are using mysql 3.23.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Delete query not working In reply to
In Reply To:
Did you read that multi table delete's are only supported in mysql 4? Most likely you are using mysql 3.23.

Cheers,

Alex


yes i read that, figured that was my problem, thats why i have given up, if it was possible i reckon i would have done it by now, i dont normally get stuck this long ever on queries.
Quote Reply
Re: [WoSkI] Delete query not working In reply to
SELECT VERSION() will give you the version of MySQL you are running.

Cheers,

Alex
--
Gossamer Threads Inc.