Slide 22
Slide 22 text
SQL 2 SQL 1
Entity Framework Core
Performance Optimization
Lets try with SQL …
Understanding Queries
SELECT
( SELECT TOP(1) p.Id FROM Products p WHERE g.Id = p.GroupId ) AS FirstProductId,
( SELECT TOP(1) p.Name FROM Products p WHERE g.Id = p.GroupId ) AS FirstProductName
FROM
ProductGroups g
SELECT p.Id, p.Name
FROM
ProductGroups g
LEFT JOIN
(
SELECT Id, Name, GroupId
FROM
(
SELECT Id, Name, GroupId, ROW_NUMBER() OVER(PARTITION BY GroupId ORDER BY Id) AS row
FROM Products
) p
WHERE row <= 1
) p ON g.Id = p.GroupId
2 sub-selects
Window function
“ROW_NUMBER”