DELETE using INNER JOIN

  • Thanks a lot.........:-)

  • Thanks for this. I was going nuts with syntax error until I saw your script that used th alias instead of the table name. Simple but brilliant!

    thanks again.:-)

  • SELECT * into #tempDocFragToDelete FROM

    DocumentFragmentRelationShipHistory WHERE DocumentFragmentMasterId =391

    AND DocumentFragmentVersionID=1.0

    DELETE a from DocumentFragmentRelationShipHistory a join #tempDocFragToDelete b

    on a.DocumentFragmentMasterId = b.DocumentFragmentMasterId

    where a.DocumentFragmentVersionID > b.DocumentFragmentVersionID

    This one is a real running example, try this.

  • Hi vikash,

    In my case I want to delete those data which is not selecting in below join any Help..

    DELETE ord FROM Orders ord INNER JOIN Customers c(nolock) ON ord.CustomerID = c.CustomerID WHERE c.FirstName = 'vikash'

    Thanks

  • forsqlserver (7/23/2012)


    Hi vikash,

    In my case I want to delete those data which is not selecting in below join any Help..

    DELETE ord FROM Orders ord INNER JOIN Customers c(nolock) ON ord.CustomerID = c.CustomerID WHERE c.FirstName = 'vikash'

    Please create a separate thread for your problem

    Also note that this is an old thread and the person you are referring to might not be online always to help you out

    If you create a new thread with some sample data and DDL of the tables invloved, I am sure there are many here who can help out in no time

    If you don't know how to do this, go through the link in my signature


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Just try below code should work as its working in sqlserver2008:

    DELETE FROM Orders

    Where exists

    (select 1 FROM Customers c WHERE Orders.CustomerID = c.CustomerID AND c.FirstName = 'vikash')

Viewing 6 posts - 16 through 20 (of 20 total)

You must be logged in to reply to this topic. Login to reply