shanetastic Posted October 6, 2011 Share Posted October 6, 2011 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 Here are my table structures: Reps ------ RepID RepName Principals ----------- PrincipalID PrincipalName States -------- StateID StateAbbreviation Territories ------------ RepID PrincipalID StateID Quote Link to comment https://forums.phpfreaks.com/topic/248585-what-is-wrong-with-this-delete-query/ Share on other sites More sharing options...
Andy-H Posted October 6, 2011 Share Posted October 6, 2011 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%' ) Quote Link to comment https://forums.phpfreaks.com/topic/248585-what-is-wrong-with-this-delete-query/#findComment-1276612 Share on other sites More sharing options...
fenway Posted October 6, 2011 Share Posted October 6, 2011 Well, you can't use "USING" in place of joins. Quote Link to comment https://forums.phpfreaks.com/topic/248585-what-is-wrong-with-this-delete-query/#findComment-1276619 Share on other sites More sharing options...
shanetastic Posted October 7, 2011 Author Share Posted October 7, 2011 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* Quote Link to comment https://forums.phpfreaks.com/topic/248585-what-is-wrong-with-this-delete-query/#findComment-1276628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.