• DEEPAK GUPTA-378433 (7/29/2016)


    Hello All

    How could I use Column for Table1 within subquery. I know this is not possible but there should be a nice way to achieve this.

    SELECT *

    FROM Table1 K1

    WHERE (1) = (

    SELECT COUNT(DISTINCT(K2.KiaId))

    FROM Table1 K2

    WHERE K2.KiaId >= K1.KiaId and K2.KiaKIID = K1.KiaKIID)

    Thanks in Advance

    Are you referring to something like this?

    SELECT *

    FROM Table1 K1

    CROSS APPLY (

    SELECT COUNT(DISTINCT(K2.KiaId)) CntDisKiaId

    FROM Table1 K2

    WHERE K2.KiaId >= K1.KiaId and K2.KiaKIID = K1.KiaKIID

    HAVING COUNT(DISTINCT(K2.KiaId)) = 1) K2

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2