Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:04:07+00:00 2026-05-31T01:04:07+00:00

I have this simple piece of sql that does exactly what I need… SELECT

  • 0

I have this simple piece of sql that does exactly what I need…

SELECT MIN(pb.Id) AS Id, MIN(pb.Quantity) AS Requested, SUM(pbi.Quantity) AS Total
FROM PickBatchItems AS pb
LEFT JOIN PickBatchItemLocations AS pbi ON pb.Id = pbi.PickBatchItemId
GROUP BY pb.Id

Results in…

Id, Requested, Total
 1    100       NULL
 2    200       165
 3    200       NULL 

This is exactly what I want but I need this to be in Linq.

So far I have…

var pick = (from pb in db.PickItems
           join pbi in db.PickItemLocations on pb.Id equals pbi.PickBatchItemId into TempJoin
           from resList in TempJoin.DefaultIfEmpty()
           where pb.Id == iPickItemId
           group resList by pb.Id into g
           select new
           {
               Id = g.Key,
               RequestedQuantity = g.Min(???????????????????????),
               SentQuantity = g.Sum(a => a.Quantity == null ? 0 : a.Quantity),
           }).FirstOrDefault();

How can I get the RequestedQuantity?

UPDATE:

Thanks to ‘David B’ I have the answer:

var pick = (from pb in db.PickBatchItems
            join pbi in db.PickBatchItemLocations on pb.Id equals pbi.PickBatchItemId into TempJoin
            from resList in TempJoin.DefaultIfEmpty()
            where pb.Id == iPickItemId
            group new { PickItem = pb, PickItemLocation = resList } by pb.Id into g
            select new
            {
                Id = g.Key,
                RequestedQuantity = g.Min(a => a.PickItem.Quantity),
                SentQuantity = g.Sum(a => a.PickItemLocation.Quantity == null ? 0 : a.PickItemLocation.Quantity),
            }).FirstOrDefault();

This joins and returns my two tables even if the PickBatchItemLocations table is empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:04:09+00:00Added an answer on May 31, 2026 at 1:04 am

    Assuming that PickItems.Id is the primary key, it seems that joining is the first step to a road that need not be traveled.

    from pb in db.PickItems
    where pb.Id = iPickItemId //this wasn't in the original sql
    select new
    {
      Id = pb.Id,
      RequestedQuantity = pb.Quantity,
      SentQuantity = pb.PickItemLocations.Sum(pbi => pbi.Quantity)
    };
    

    If you still want to take the long road, do this:

    group new {PickItem = pb, PickItemLocation = resList } by pb.Id into g
    select new
    {
      Id = g.Key,
      RequestedQuantity = g.Min(x => x.PickItem.Quantity),
      SentQuantity = g.Sum(x => x.PickItemLocation.Quantity ?? 0)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple piece of code that returns what's in the title. Why
I have this simple piece of code that uses boost::bind: #include <boost/bind.hpp> #include <utility>
I've wrote this simple piece of code. And I have a slight problem with
I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
Im new to cursors in Oracle. I have a piece of SQL that is
I have a simple piece of code in a .NET console application that tries
I have a piece of SQL that works out the rank of a golfer
OneWayToSource Binding seems broken in .NET 4.0 I have this simple piece of Xaml
I have this simple html piece of code, whenever I click on any of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.