sql Delete

Posted on 2007-08-02
Last Modified: 2010-03-19
I have two tables Master,Detail related on Master.sLink and detail.slink. I need to delete rows in master that do NOT appear in Detail.

Ive been messing with this all morning and need some guidence.
Question by:stephenz43
    LVL 142

    Accepted Solution

    delete master
    where not exists ( select null from detail where detail.slink = master.slink )
    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    delete from [Master] m
    WHERE NOT EXISTS (SELECT 1 from Detail where sLink = m.slink)


    DELETE FROM [Master]
    WHERE sLink NOT IN (SELECT slink FROM Details)

    Author Comment

    thank you

    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: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
    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.​
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now