Solved

SQL Syntax - Delete Records based on another tables data

Posted on 2010-09-08
3
305 Views
Last Modified: 2012-05-10
Hi

I have the following 2 tables:

tblProducts
Columns: ProductType, ReleaseDate, CustomerType

tblDormantProducts
Columns: ProductType, DateFrom, DateTo, CustomerType

How could I create an SQL DELETE statement to delete records from tblProducts based on records that match within tblDormantProducts?...

with tblProducts.ReleaseDate, this needs to match between tblDormantProducts.DateFrom and tblDormantProducts.DateTo.

Many thanks,

Rit
0
Comment
Question by:rito1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33628560
DELETE FROM tblProducts
FROM tblProducts p INNER JOIN
    tblDormantProducts d ON p.ProductType = d.ProductType
WHERE p.ReleaseDate BETWEEN d.DateFrom AND d.DateTo
0
 
LVL 30

Expert Comment

by:hnasr
ID: 33631808
Ceck this replace with your table and field names.
Table A (a, x)
Table B (a, b, x1, x2)

DELETE  * FROM A
WHERE A.a
IN (SELECT  A.a
FROM A INNER JOIN B ON A.a = B.a
WHERE A.x Between B.x1 AND B.x2)
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 33637235
Thanks both but I went with matthewspatrick purely because I set to work on his syntax and it all made sense to me as I was implementing.

many thanks,

Rit
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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