Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Delete Rows From Database

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
Gunit2507
Asked:
Gunit2507
  • 2
1 Solution
 
spprivateCommented:
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
 
Gunit2507Author Commented:
The other database doesn't have an employee ID or any value like that... So how would that look in SQL?
0
 
spprivateCommented:
you can use the same query as i mentioned earlier
0
 
anyoneisCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now