SQL : Delete with joining to other table

Actually I’m not sure how to write this topic. Previously, i need to delete from one table and also need to check a condition from other table. I think there is a few ways to do that.

For a normal delete statement, our code should be.

DELETE FROM TABLE_A WHERE {Condition Here}

I just found out that we can do it this way.

DELETE TABLE_A
FROM TABLE_A , TABLE_B
WHERE TABLE_B.Month = 1 and TABLE_B.Year = 2007
AND TABLE_A.P1 = TABLE_B.P1
AND TABLE_A.P2 = TABLE_B.P2

This sql statement valid for Microsoft SQL. I’m not yet test this on other database.

If you're new here, you may want to subscribe to my RSS feed or get my latest post directly in your mailbox. Thanks for visiting !

Related Post:
  • MS-SQL - List trigger in your db.
  • Truncate or Delete ?
  • Utilizing ms sql temporary table
  • MSSQL - Useful query for my reference
  • MyBlogLog : my first lesson



  • Can't find what you are looking for? Go Gooogle...
    Google

    Leave a Reply


    AWSOM Powered