Sub query optimization

  • is there any other BETTER way to write the following query??

    SELECT

    T_1.COLUMN_1

    , T_1.COLUMN_2

    , T_1.COLUMN_3

    , SUM(T_1.COLUMN_4)

    FROM TABLE_1 T_1WHERE NOT EXISTS(SELECT T_2.COLUMN_1 FROM TABLE_2 T_2WHERE T_1.COLUMN_1 = T_2.COLUMN_1 )

    AND T_1.COLUMN_1 != 'None'

    GROUP BY T_1.COLUMN_1, T_1.COLUMN_2, T_1.COLUMN_3

    i dont want to use subquery

    please help

  • mohd.imtiaz (12/10/2008)


    i dont want to use subquery

    Why not?

    Is the query too slow? It is using excessive resources? Causing blocking?

    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
  • If you check out this thread you'll see that method you are using is the consensus pick for best performing.

    Of course as Gail asked, why do you want to avoid the subquery?

  • Its a correlated sub query, and i have gone through may site which says corelated syb queries work very slow.

    is tht true??

    guide me

  • mohd.imtiaz (12/11/2008)


    Its a correlated sub query, and i have gone through may site which says corelated syb queries work very slow.

    is tht true??

    In most cases (including this one) no. The optimiser is perfectly capable of handling most correlated queries in an efficient manner.

    The one time where correlated subqueries are slow is when the comparison with the outer query is an inequality

    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

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply