开发者

select minimum quantity where productID =1

开发者 https://www.devze.com 2023-03-13 20:31 出处:网络
i am working on asp .net mvc3. i have following table i want to sele开发者_如何学Cct minimum quanity where ProductID=1

i am working on asp .net mvc3. i have following table

select minimum quantity where productID =1

i want to sele开发者_如何学Cct minimum quanity where ProductID=1

please help to find out the exact query for above requirement.


EDIT: Use Min method:

 var results = db.ProductTable.Where(r => r.productId == 1).Min(r=> r.Quantity);

I'm not sure how you are accessing your data or where it is stored but something like this:

SQL:

SELECT MIN(Quantity) FROM table where ProductId=1

LINQ is something like this:

var minQuantity = from P In Products
                    Where P.ProductId = 1
                    select Min(P.Quantity)


context.table.where(q=>q.productid=1).Select(k => k).Min(k=>k.quantity)

it's important to note that min is a client side function meaning it will execute min algo on the records returned in your program not in SQL which is not a recommended approach if by any means your dataset is a big collection then it will retrieve all those records and then will find the minimum value to return.

you can read more here

0

精彩评论

暂无评论...
验证码 换一张
取 消