Solved

ASP.NET query to delete

Posted on 2012-04-10
2
339 Views
Last Modified: 2012-06-22
I need a query that deletes everything from the "Names" table but only where where is not a matching ID in the "Departments" table.  So in the example below, ID's 1, 3 and 6 would  be deleted, but ID's 2, 4 and 5 would not be deleted.  I can't figure out the query.

   Names                                                    Departments

ID     Name                                           ID            Department
==     =====                                          ==            ==========
1       Smith                                          2               Accounting
2       Jones                                           4               Management
3       Miller                                          5               Purchasing
4       Washington
5       Lewis
6       Brown
0
Comment
Question by:zintech
2 Comments
 
LVL 15

Expert Comment

by:Anuj
ID: 37828225
DELETE FROM Name
FROM Names N
INNER JOIN Department M
ON M.ID = N.ID
WHERE N.ID IS NULL
0
 
LVL 5

Accepted Solution

by:
hafeezmca earned 500 total points
ID: 37828340
Hi try this:

delete from names where Id not in (select e.Id from Names e, Departmentt d where e.Id=d.Id)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now