You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[UnitsInStock]
FROM [Products] AS [p]
WHERE (
SELECT CASE
WHEN EXISTS (
SELECT1FROM (
SELECT [o].[OrderID], [o].[ProductID]
FROM [Order Details] AS [o]
WHERE [p].[ProductID] = [o].[ProductID]
) AS [t]
INNER JOIN (
SELECT TOP(1) [orderDetail].[OrderID], [orderDetail].[ProductID]
FROM [Order Details] AS [orderDetail]
WHERE [orderDetail].[Quantity] =1
) AS [t0] ON ([t].[OrderID] = [t0].[OrderID]) AND ([t].[ProductID] = [t0].[ProductID]))
THEN CAST(1ASBIT) ELSE CAST(0ASBIT)
END
) =1
In cases where the Inner Join is on the same table, it may be possible to eliminate the join
SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[UnitsInStock]
FROM [Products] AS [p]
WHERE (
SELECT CASE
WHEN EXISTS (
SELECT1FROM (
SELECT TOP(1) [orderDetail].[ProductID]
FROM [Order Details] AS [orderDetail]
WHERE [orderDetail].[Quantity] =1
) AS [t]
WHERE [p].[ProductID] = [t].[ProductID])
THEN CAST(1ASBIT) ELSE CAST(0ASBIT)
END
) =1
The text was updated successfully, but these errors were encountered:
When a sub query uses Contains on a navigation, like the following:
The SQL contains an inner join on the same table:
In cases where the Inner Join is on the same table, it may be possible to eliminate the join
The text was updated successfully, but these errors were encountered: