Solved

SQL Delete query where = sub-query

Posted on 2009-06-29
2
540 Views
Last Modified: 2013-12-07
Hello,
I'm trying to delete all the rows from table A where the Acc num matches the same account number from table B.

Tried the 23 queries below but they don't want to run

Any one know how to correct them?

First Attempt
 

DELETE A.*

FROM A, B

WHERE A.ACC_NUM=B.ACC_NUM=
 

Second Attempt
 

DELETE A.*

FROM A

WHERE A.ACC_NUM=(SELECT ACC_NUM

                                    FROM B);

Open in new window

0
Comment
Question by:ShockUK
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
use IN instead of =
DELETE A.*
FROM A
WHERE A.ACC_NUM IN (SELECT ACC_NUM
                                    FROM B);

Open in new window

0
 
LVL 5

Expert Comment

by:mnialon
Comment Utility
DELETE
FROM A
WHERE A.ACC_NUM IN (SELECT ACC_NUM
                                    FROM B);
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now