Re: SQL Update query
From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 08/18/04
- Previous message: Tom: "Re: SQL Update query"
- In reply to: Tom: "Re: SQL Update query"
- Next in thread: Tom: "Re: SQL Update query"
- Reply: Tom: "Re: SQL Update query"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Aug 2004 02:56:17 +0530
hi tom,
Internally in and exists clauses are evaluated differently.In clause is
internally evaluated as multiple OR conditions. Whereas EXISTS clause checks
for the subquery returns at least one row.
This is typical scenario when checking non-existing rows from the table.
select * from customers
where customerid not in(select customerid from orders union all select null)
If any of the rows from the subquery returns null value and if you are using
NOT IN clause then you will get any empty resultset.
You can use NOT EXISTS clause or LEFT OUTER JOIN to get the required result
set.
1st method:
select * from customers
where not exists
(select * from
(select distinct customerid from orders union all select null) a
where a.customerid = customers.customerid
)
2nd method:
select a.*
from customers a left outer join
(select distinct customerid from orders union all select null)b
on a.customerid = b.customerid
where b.customerid is null
-- Vishal Parkar vgparkar@yahoo.co.in | vgparkar@hotmail.com
- Previous message: Tom: "Re: SQL Update query"
- In reply to: Tom: "Re: SQL Update query"
- Next in thread: Tom: "Re: SQL Update query"
- Reply: Tom: "Re: SQL Update query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|