Solved

SQL Delete query where = sub-query

Posted on 2009-06-29
2
544 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24734488
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
ID: 24734495
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

860 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