SELECT * FROM tblGroup a
INNER JOIN (
SELECT * FROM tblGroupMatrix where GroupMatrixId
IN (
SELECT MIN(GroupMatrixId) OVER (PARTITION BY GroupId)
FROM tblGroupMatrix)) b
ON a.GroupId=b.GroupId
OPTIMIZED :
SELECT *
FROM tblGroup A
INNER JOIN tblGroupMatrix B ON A.GroupId = B.GroupId
WHERE GroupMatrixId = ( SELECT MIN(GroupMatrixId)
FROM tblGroupMatrix
WHERE GroupId = A.GroupId)
INNER JOIN (
SELECT * FROM tblGroupMatrix where GroupMatrixId
IN (
SELECT MIN(GroupMatrixId) OVER (PARTITION BY GroupId)
FROM tblGroupMatrix)) b
ON a.GroupId=b.GroupId
OPTIMIZED :
SELECT *
FROM tblGroup A
INNER JOIN tblGroupMatrix B ON A.GroupId = B.GroupId
WHERE GroupMatrixId = ( SELECT MIN(GroupMatrixId)
FROM tblGroupMatrix
WHERE GroupId = A.GroupId)
No comments:
Post a Comment