Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Location
    Weatherford TX (Between Fort Worth and Abilene)
    Posts
    57

    Unanswered: Delete Query Using Join

    I need to delete records from one table base on criteria from another table. The example below from the Northwind database shows exactly what I want to do. I want to delete the records from the employee table who a terrorityID of 30346 in the EmployeeTerritories table.

    Can someone tell me how to write a delete statement that will delete the rows returned from the following SQL Statement? The sql statement will return one employee name. I would lke to delete that one employee from the employee table and I haven’t been able to figure out how to do it.

    ////////// Sql Statment
    SELECT dbo.EmployeeTerritories.EmployeeID, dbo.EmployeeTerritories.TerritoryID
    FROM dbo.EmployeeTerritories INNER JOIN
    dbo.Employees ON dbo.EmployeeTerritories.EmployeeID = dbo.Employees.EmployeeID
    WHERE (dbo.EmployeeTerritories.TerritoryID = N'30346')
    ////////// end of sql statement

    Thanks
    GEM

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Remove the select clause and replace with a delete clause. Your delete clause needs to include the name of the table you want to delete from.

    Assuming of course you want to use the T-SQL extension rather than SQL standard syntax:
    http://msdn2.microsoft.com/en-US/lib...7(SQL.80).aspx
    As ever, BoL is the best starting point
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Feb 2004
    Posts
    193
    DELETE dbo.EmployeeTerritories
    FROM dbo.EmployeeTerritories
    JOIN dbo.Employees
    ON dbo.EmployeeTerritories.EmployeeID = dbo.Employees.EmployeeID
    WHERE (dbo.EmployeeTerritories.TerritoryID = N'30346')

    --ddave

  4. #4
    Join Date
    Aug 2012
    Posts
    1
    Thanks, Dave's answer works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •