"NOT IN" REPLACE WITH "MINUS"

  • 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?

  • 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

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Looks like an academic / interview question.

    -- Gianluca Sartori

  • To optimize the query

  • if it is just to optimize why dont u use Merge for it??

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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