DEEPAK GUPTA-378433 (7/29/2016)
Hello AllHow 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