Jump to content

What is wrong with this DELETE query


shanetastic

Recommended Posts

I am getting this error: 

 

[Err] 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 'DELETE FROM Territories
USING Territories, Reps, States, Principals
WHERE Terr' at line 1

 

When I try to run this query:

 

DELETE FROM Territories
USING Territories, Reps, States, Principals
WHERE Territories.RepID = Reps.RepID
AND Territories.PrincipalID = Principals.PrincipalID
AND Territories.StateID = States.StateID
AND Reps.RepName = 'CompanyA'
AND Principals.PrincipalName = 'CompanyB'
AND States.StateAbbreviation LIKE '%NC%';

 

What am I doing wrong  :confused:

 

Here are my table structures:

 

Reps
------
RepID
RepName


Principals
-----------
PrincipalID
PrincipalName


States
--------
StateID
StateAbbreviation

Territories
------------
RepID
PrincipalID
StateID

Link to comment
https://forums.phpfreaks.com/topic/248585-what-is-wrong-with-this-delete-query/
Share on other sites

Do you mean:

 

 

DELETE t.* FROM Territories t
INNER JOIN ( Reps r, States s, Principals p )
ON
( t.RepID = r.RepID AND t.PrincipalID = p.PrincipalID AND t.StateID = s.StateID )
WHERE
( r.RepName = 'CompanyA' AND p.PrincipalName = 'CompanyB' AND s.StateAbbreviation LIKE '%NC%' )

First, thank you both for your responses.  However, it turns out my original query works fine...it was more of an id10t error.

 

I was using the "explain" button in Navicat thinking it was a trace button (I didn't want to actually run the delete until I had all the bugs worked out).  I did not realize that that EXPLAIN is an actual mysql command....and that that command isn't compatible with DELETE  *facepalm*

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.