Solved

ASP.NET query to delete

Posted on 2012-04-10
2
338 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

707 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

14 Experts available now in Live!

Get 1:1 Help Now