Subject | Deifference between IN and EXISTS |
---|---|
Author | Vishal Tiwari |
Post date | 2009-09-14T13:45:15Z |
Hi All,
Is there anything wrong with EXISTS predicate and IN predicate
Anybody can tell me where i am making mistake in query no. 2.
Only Query no. 1 deletes certain records and Query no. 2 deletes no records.
will EXISTS predicate give benifit in query no. 2, means can delete any records with some modification in query no. 2.
Both the queries are given below.
regards
Have A Nice Day.
Vishal Tiwari...
*******************************
Query No.1:
Delete from Table_C C
where
C.dt_date <= '03/01/2007'
And
C.var_EmpCode not In (
select var_EmpCode from Table_A A
join Table_B B
On
A.var_EmpCode = B.var_EmpCode
And
A.var_PGCode = B.var_PGCode
And
(A.var_Status = 'I'
or
A.var_Resigned_ But_Not_Settled = 'Y') )
and Max(B.dt_AppliedDat e) <= '03/31/2007' );
Query No.2:
Delete from Table_C C
where
C.dt_date <= '03/01/2007'
And
not exists (
select var_EmpCode from Table_A A
join Table_B B
On
A.var_EmpCode = B.var_EmpCode
And
A.var_PGCode = B.var_PGCode
And
(A.var_Status = 'I'
or
A.var_Resigned_ But_Not_Settled = 'Y') )
and Max(B.dt_AppliedDat e) <= '03/31/2007' );
See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/
[Non-text portions of this message have been removed]
Is there anything wrong with EXISTS predicate and IN predicate
Anybody can tell me where i am making mistake in query no. 2.
Only Query no. 1 deletes certain records and Query no. 2 deletes no records.
will EXISTS predicate give benifit in query no. 2, means can delete any records with some modification in query no. 2.
Both the queries are given below.
regards
Have A Nice Day.
Vishal Tiwari...
*******************************
Query No.1:
Delete from Table_C C
where
C.dt_date <= '03/01/2007'
And
C.var_EmpCode not In (
select var_EmpCode from Table_A A
join Table_B B
On
A.var_EmpCode = B.var_EmpCode
And
A.var_PGCode = B.var_PGCode
And
(A.var_Status = 'I'
or
A.var_Resigned_ But_Not_Settled = 'Y') )
and Max(B.dt_AppliedDat e) <= '03/31/2007' );
Query No.2:
Delete from Table_C C
where
C.dt_date <= '03/01/2007'
And
not exists (
select var_EmpCode from Table_A A
join Table_B B
On
A.var_EmpCode = B.var_EmpCode
And
A.var_PGCode = B.var_PGCode
And
(A.var_Status = 'I'
or
A.var_Resigned_ But_Not_Settled = 'Y') )
and Max(B.dt_AppliedDat e) <= '03/31/2007' );
See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/
[Non-text portions of this message have been removed]