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 > Database Server Software > Oracle > Deleting rows from table based on value from other table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-23-11, 10:43
suddublr suddublr is offline
Registered User
 
Join Date: Nov 2011
Posts: 2
Deleting rows from table based on value from other table

Hello Members,

I am struck to solve the issue said below using query. Would appreciate any suggestions...

I have two tables having same structures. I want to delete the rows from TableA ( master table ) with the values from TableB ( subset of TableA). The idea is to remove the duplicate values from tableA. The data to be removed are present in TableB. Catch here is TableB holds one row less than TableA, for example
Table A
--------
Name Value
-------------
Test 1
Test 1
Test 1
Hello 2
Good 3

TableB
-------------
Name Value
----------------
Test 1
Test 1

The goal here is to remove the two entries from TableB ('Test') from TableA, finally leaving TableA as
Table A
--------
Name Value
-------------
Test 1
Hello 2
Good 3

I tried below queries
1. delete from TestA a where rowid = any (select rowid from TESTA b where b.Name = a.Name and a.Name in ( select Name from TestB ));

Any suggestions..

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 11-23-11, 10:55
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
>The idea is to remove the duplicate values from tableA.
Then why is tableB needed?
Why do duplicate value exist within tableB? Does TableB need to have duplicates removed from it?
If not, why not.
P.S.
Lousy homework assignment.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 11-23-11, 11:25
suddublr suddublr is offline
Registered User
 
Join Date: Nov 2011
Posts: 2
Thanks.

Well, the issue I mentioned is a part of the process. The thing is TableB contains the duplicate values which should be deleted from TableA. So that we know what all values we have deleted from TableA. On deleted TableA if I later insert the value from TableB I should be getting the original TableA...
Reply With Quote
  #4 (permalink)  
Old 11-23-11, 11:38
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 11-23-11, 13:34
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
Reply

Tags
delete rows

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