Skip to content
Advertisement

Write a SQL query with a subquery in .NET Core using Entity Framework that returns a list of items with varying number of returned child rows

I have this test SqlFiddle: http://sqlfiddle.com/#!18/05fce/1

The idea is that for each product (table webspiderproduct) it will return the lowest price from each shopId from the table webspiderproductprice.

So the returned data should look like this:

I am using SQL Server.

In pseudocode should I write a

and then do a foreach through each row using linq and then add the child rows from webspiderproductprice or should I do a join query ?

Advertisement

Answer

Use the following code:

Output:

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement