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
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%' )

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.