Solved

Delete Rows From Database

Posted on 2009-04-09
4
186 Views
Last Modified: 2012-05-06
Hello,
I have two tables (Employees and Records) that both contain a FirstName and LastName column.  I want to create a Delete Query that will delete every row in the Employee's table where a data row's FirstName and LastName is not found in the Records table.
0
Comment
Question by:Gunit2507
  • 2
4 Comments
 
LVL 15

Expert Comment

by:spprivate
Comment Utility
delete from employees where firstname+lastname not in
(select firstname+lastname from records).
But I would say this is a bad design and rather I would have Emp ID as a key in the child table and delete by the id.
0
 

Author Comment

by:Gunit2507
Comment Utility
The other database doesn't have an employee ID or any value like that... So how would that look in SQL?
0
 
LVL 15

Expert Comment

by:spprivate
Comment Utility
you can use the same query as i mentioned earlier
0
 
LVL 11

Accepted Solution

by:
anyoneis earned 500 total points
Comment Utility
Just a minor addition: it is possible that simply concatenating first and last names could result in a false match. To ensure this doesn't happen, connect the two wih a delimiter, as in:

delete from employees where firstname + '|' + lastname not in
(select firstname + '|' + lastname from records).


David

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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