Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2003, 09:48 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please change to Delete SQL without Join

Please let me know what the SQL statement will be if I don't use JOIN keyword. I created it, but it doesn't work well.

Thanks,


DELETE Location.*
FROM Location INNER JOIN Project ON Location.LocationID = Project.LocationID
WHERE (((Project.ProjectID)=2));

 
Old December 11th, 2003, 05:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can only name one table in the FROM clause of a DELETE SQL statement. One way to get your query to work is with a sub-query.
Code:
DELETE FROM Location
      WHERE LocationID IN (SELECT LocationID
                             FROM Project
                            WHERE ProjectID = 2)
                            I am sure there are plenty of other ways (probably even faster ways) or doing what you want, however this query should work as you need.

Regards
Owain Williams
 
Old December 11th, 2003, 07:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

SQL Server defines an extension to the DELETE syntax which allows you to specify a JOIN which defines the rows to be deleted:
Code:
DELETE Location
FROM Location INNER JOIN Project
    ON Location.LocationID = Project.LocationID
WHERE Project.ProjectID=2;
will work, but this is non-standard, and so it probably isn't available on any other RDBMS. Owain's method of using a sub-query is best (and fastest), IMO.


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old December 12th, 2003, 03:16 AM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, Owain and Jeff. That helps a lot.

 
Old December 12th, 2003, 03:29 AM
Registered User
 
Join Date: Dec 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DELETE L
FROM Location L JOIN Project P ON L.LocationID = P.LocationID
AND P.ProjectID=2






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL INNER JOIN problem lawsoncobol Access VBA 1 August 17th, 2006 02:29 PM
SQL join problem mattastic SQL Language 2 May 26th, 2005 08:27 AM
SQL Join mattastic SQL Server 2000 9 April 21st, 2005 10:27 AM
Please change the SQL to the one without JOIN kaz SQL Language 4 December 9th, 2003 05:51 PM
Cannot modify (add/change/delete) data jandarby Classic ASP Databases 9 June 4th, 2003 06:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.