Results 1 to 7 of 7
  1. #1
    Join Date
    May 2007
    Posts
    7

    Unanswered: Help on delete statement

    Hi,
    I have two tables.
    Table1:
    MySymbol, BloombergSymbol
    A, A_Bloomberg
    B, B_Bloomberg

    Table2:
    MySymbol, Open, High, Low, Close
    A,...
    A,...
    B,...
    B,...

    I want to perform one task--Delete all the records in table2 whose MySymbol matches one given BloombergSymbol in table1.

    3x.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    which dbms is this?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2005
    Posts
    30
    Try this query:

    Code:
    Delete Table2.* from Table1 LEFT JOIN Table2 ON Table1.MySymbol = Table2.MySymbol

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Alternate syntax :

    Code:
    DELETE FROM table2 WHERE MySymbol IN (SELECT MySymbol FROM table1)
    n.b. I have based this on MySQL syntax which may or may not work in your DB.

  5. #5
    Join Date
    May 2007
    Posts
    7
    sql server
    Quote Originally Posted by r937
    which dbms is this?

  6. #6
    Join Date
    May 2007
    Posts
    7
    this one works.
    thank you guys.

    Quote Originally Posted by aschk
    Alternate syntax :

    Code:
    DELETE FROM table2 WHERE MySymbol IN (SELECT MySymbol FROM table1)
    n.b. I have based this on MySQL syntax which may or may not work in your DB.

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    For SQL Server use:

    DELETE table2
    FROM table2
    INNER JOIN table1 ontable2.MySymbol = table1.MySymbol
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •