If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Help on delete statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-07, 17:14
stian1 stian1 is offline
Registered User
 
Join Date: May 2007
Posts: 7
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.
Reply With Quote
  #2 (permalink)  
Old 06-04-07, 20:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
which dbms is this?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-05-07, 03:05
ashish_mat1979 ashish_mat1979 is offline
Registered User
 
Join Date: Aug 2005
Posts: 30
Try this query:

Code:
Delete Table2.* from Table1 LEFT JOIN Table2 ON Table1.MySymbol = Table2.MySymbol
__________________
Ashish
Entertainment Overloaded
Reply With Quote
  #4 (permalink)  
Old 06-06-07, 03:44
aschk aschk is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 06-06-07, 10:04
stian1 stian1 is offline
Registered User
 
Join Date: May 2007
Posts: 7
sql server
Quote:
Originally Posted by r937
which dbms is this?
Reply With Quote
  #6 (permalink)  
Old 06-06-07, 10:06
stian1 stian1 is offline
Registered User
 
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.
Reply With Quote
  #7 (permalink)  
Old 06-06-07, 13:28
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
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"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On