loveindia Posted September 25, 2014 Report Posted September 25, 2014 I don't know what are the needs but modify the query like this.. ;WITH cte AS ( select -1 AS a, u.ID AS [uid], -1 AS b, g.ID AS [gid], g.Name, RANK() OVER (PARTITION BY u.ID ORDER BY u.ID) AS [Rank] from vwUsers u join vwGroups g on g.Name = 'abc' join vwOrders o on o.ShipToID = u.LinkID and o.ProductID = 123 ) SELECT a, [uid], b, [gid] FROM CTE WHERE RANK = 1
sqlhelp Posted September 25, 2014 Author Report Posted September 25, 2014 I don't know what are the needs but modify the query like this.. ;WITH cte AS ( select -1 AS a, u.ID AS [uid], -1 AS b, g.ID AS [gid], g.Name, RANK() OVER (PARTITION BY u.ID ORDER BY u.ID) AS [Rank] from vwUsers u join vwGroups g on g.Name = 'abc' join vwOrders o on o.ShipToID = u.LinkID and o.ProductID = 123 ) SELECT a, [uid], b, [gid] FROM CTE WHERE RANK = 1 This helped thank you all..
arshad Posted September 25, 2014 Report Posted September 25, 2014 group by use cheyacha? Happy ga use cheyyi.. adi kooda distinct istadi.
Recommended Posts