September 15, 2011 at 1:48 am
How do i change this query with A MINUS OPERATOR
select * from a where id
not in (select a_id from b)
Do you have an idea?
September 15, 2011 at 2:08 am
It doesn't make sense IMHO.
However...
select *
from a
except
select *
from a
where id in (select a_id from b)
It would be much more sensible if you selected id only:
select id
from a
except
select a_id
from b
Hope this helps
Gianluca
-- Gianluca Sartori
September 15, 2011 at 3:40 am
Thinky Night (9/15/2011)
How do i change this query with A MINUS OPERATOR?
Why would you want to?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 15, 2011 at 3:44 am
Looks like an academic / interview question.
-- Gianluca Sartori
September 15, 2011 at 4:40 am
To optimize the query
September 15, 2011 at 4:49 am
if it is just to optimize why dont u use Merge for it??
September 15, 2011 at 5:00 am
Thinky Night (9/15/2011)
To optimize the query
It's not likely to be more efficient and it could change the meaning of the query.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 15, 2011 at 5:01 am
padhu.mukku (9/15/2011)
if it is just to optimize why dont u use Merge for it??
Merge is a data modification statement, not a more optimal version of NOT IN
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 15, 2011 at 5:54 am
Thinky Night (9/15/2011)
To optimize the query
Honestly, I don't think it would run faster with EXCEPT.
I would look into other things first.
Do you have an execution plan to share?
-- Gianluca Sartori
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply