sql - Return master rows based on detail filter -
I have a query where I want to return the master lines, depending on whether the extension meets certain criteria .
For example, I want to return only a special master line if at least one extension rows have someProperty = X.
Based on the following determination:
Predicate = predicate.And (p = & gt; p.basketItems.Where (obi = & gt; obi.basketItemTypeID == (Int) basketball type. Refund. Count ()> gt; 0);
Generates the following SQL:
SELECT COUNT (*) FROM [dbo] [BasketetTemplate] AS [T3] WHERE ([T3]. [Basket ID] = [T.]. [Orderbosacetid]] and ([T3]. [TokiTyType ID] = 3)))) 0)
This is scanning a table, so the query may take some time to run.
Just by checking that I am not doing anything crazy, I wonder if there is something that can trigger this query?
Thanks Duncan
M.basketID, max (M.field1 ) As field1, max (M.field2) as d2.basketItems as field 2, connect to the extension on M.basketID = detail.basketID, where detail.basketItemTypeID = '3' group M.basketID < / Code>
(Connect to Master in detail. Select all the rows where the required criteria are in detail. As a result press the rows down from 1 to record per owner.)
Comments
Post a Comment