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 7903697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:48:55+00:00 2026-06-03T09:48:55+00:00

How can I do this in LINQ? select * from customer c left join

  • 0

How can I do this in LINQ?

select
    *
from customer c
left join order o on o.CustomerID = c.CustomerID
where o.OrderDate = (select MAX(OrderDate) from order where CustomerID = o.CustomerID )

not worried about dups as there will always only be one order per day.

I got as far as the left join in LINQ, but not sure how or where to put the subquery in.

var query = from customer in clist
            from order in olist
                .Where(o => o.CustomerID == customer.CustomerID)
            select new {
                customer.CustomerID,
                customer.Name,
                customer.Address,
                Product = order != null ? order.Product : string.Empty
            };

FINAL SOLUTION:

var query = from customer in clist
            from order in olist
            .Where(o => o.CustomerID == customer.CustomerID && o.OrderDate ==
                olist.Where(o1 => o1.CustomerID == customer.CustomerID).Max(o1 => o1.OrderDate)
            )
            select new {
                customer.CustomerID,
                customer.Name,
                customer.Address,
                order.Product,
                order.OrderDate
            };

Another solution without any lambdas

var query = from customer in clist
            from order in olist 
            where order.CustomerID == customer.CustomerID && order.OrderDate == 
                (from o in olist 
                 where o.CustomerID == customer.CustomerID 
                 select o.OrderDate).Max()
            select new {
                customer.CustomerID,
                customer.Name,
                customer.Address,
                order.Product,
                order.OrderDate
            };
  • 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-06-03T09:48:57+00:00Added an answer on June 3, 2026 at 9:48 am

    This is more or less a literal translation

    var query = from customer in clist
                from order in olist
                    .Where(o => o.CustomerID == customer.CustomerID &&
                                o.OrderDate == olist
                                    .Where(o => o.CustomerID == customer.CustomerID)
                                    .Select(o => o.OrderDate).Max())
                select new {
                    customer.CustomerID,
                    customer.Name,
                    customer.Address,
                    Product = order != null ? order.Product : string.Empty
                };
    

    but I would rewrite to

    var query = from customer in clist
                from order in olist
                    .Where(o => o.CustomerID == customer.CustomerID)
                    .OrderByDescending(o => o.OrderDate).Take(1)
                select new {
                    customer.CustomerID,
                    customer.Name,
                    customer.Address,
                    Product = order != null ? order.Product : string.Empty
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to translate this to LINQ: select stuff FROM history INNER JOIN
SELECT * FROM Customer WHERE Name 'LIKE [a-f]%' How Can I acheive this in
Can I have some help in improving this linq. I'm basically returning speakers from
var customer= from cust in customerData select new Customer { CustomerID = cust[id], Name
SQL query: select ApplicationNumber,pri_indicator,count(*) from customer group by ApplicationNumber,pri_indicator How do I do this
How can I convert this query to linq to entities with entity framework: SELECT
The following SQL SELECT * FROM customers converted to this in LINQ var customers
I can't quite figure out why this Linq Statement isn't working as i would
How can I write a query similar to this one in LINQ to SQL
I have this code in Linq. Anybody can provide the t-sql. thanks! var tsr

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.