?
Solved

SQL Delete query where = sub-query

Posted on 2009-06-29
2
Medium Priority
?
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

777 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