Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL delete command

Posted on 2011-03-03
4
Medium Priority
?
338 Views
Last Modified: 2012-05-11
How can I check if parts from Table1 exists in Table2 and Table3 before delete record from Table1?

Table1
partno partname


Table2
partno iQty

Table3
partno oQty

How can I write a single sql statment to check the existence of table1's partno in table2 and table2 and if not exists delete record from Table1.

thanks

ayha
0
Comment
Question by:ayha1999
[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
4 Comments
 
LVL 15

Expert Comment

by:derekkromm
ID: 35030710
delete t1
from table1 t1
left join table2 t2
on t1.partno = t2.partno
left join table3 t3
on t1.partno = t3.partno
where t2.partno is null and t3.partno is null
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 35030725
delete fom table1 t1 wherenot exists (select 1 from (
select partno from table2 union select partno from tale3 ) t on t1.patno = t.partno)
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35030728

delete from Tbale1
where partno = your number
and not exists (select 1 from Table2 B
                       where B.partno = A.partno)

0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 1000 total points
ID: 35033778
To delete existing records in Table2 and Table3

delete from Table1
whete Table1.partno in
( Select partno from table2 union Select partno from table3)

To delete not existing records in Table2 and Table3

delete from Table1
whete Table1.partno not in
( Select partno from table2 union Select partno from table3)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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