SELECT b.*, a.Salary FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY Salary DESC) AS RowNum FROM Customer2 ) AS a JOIN Customer1 b ON a.ID = b.ID WHERE a.RowNum = 2
;WITH CTE AS( SELECT E.* ,D.Salary ,ROW_NUMBER()OVER(PARTITION BY E.Dept ORDER BY D.Salary DESC) AS RN FROM Customer1 AS E INNER JOIN Customer2 AS D ON (E.ID=D.ID) ) SELECT ID,Dept,Design,Salary FROM CTE WHERE RN=2
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)