|
|
| Author |
Message |
chan2004
New User
Joined: 28 Mar 2007 Posts: 15 Location: India
|
|
|
|
Hi,
I want to delete all records from a table A after comparing it with another table,B.
Both tables have same structure.
They have a column called 'name'.
if a row is there that contains a value of 'john' in name field of table A and there is no such value in table B, i need to delete it from table A
how to delete all such rows with one sql command?
will this sql work
DELETE FROM tableA
WHERE
ID = :id
AND
NAME not in
(SELECT NAME FROM tableB)
;
will this delete all rows? |
|
| Back to top |
|
 |
References
|
Posted: Mon May 05, 2008 12:34 pm Post subject: Re: Delete after comparing b/w two tables |
 |
|
|
 |
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1017 Location: Bangalore,India
|
|
|
|
Hello Chan,
I have just viewing ur query but unable to understand why u have used ID Col.
| Quote: |
DELETE FROM tableA
WHERE
AND
NAME not in
(SELECT NAME FROM tableB)
; |
I think below query is sufficent
| Code: |
DELETE FROM tableA
WHERE
NAME not in
(SELECT NAME FROM tableB)
; |
|
|
| Back to top |
|
 |
chan2004
New User
Joined: 28 Mar 2007 Posts: 15 Location: India
|
|
|
|
[quote="guptae"]Hello Chan,
I have just viewing ur query but unable to understand why u have used ID Col.
| Quote: |
DELETE FROM tableA
WHERE
AND
NAME not in
(SELECT NAME FROM tableB)
; |
I think below query is sufficent
thanks ekta for confirming the query
the id is just another condition that i need to check before deleting  |
|
| Back to top |
|
 |
|
|