Solved

SQL Delete query where = sub-query

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

Suggested Solutions

Title # Comments Views Activity
Bash Script to Analyze Oracle Schemas 11 108
oracle 11g 23 84
Character matching different date formats for dates between 6 48
Oracle Insert not working 10 28
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to recover a database from a user managed backup

822 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