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

  • Home
  • SEARCH
  • 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 6954447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:36:27+00:00 2026-05-27T14:36:27+00:00

Let’s say I’ve got a table called [Items] which has a primary key ItemID

  • 0

Let’s say I’ve got a table called [Items] which has a primary key ItemID, and I’ve got a table called [ItemStatuses] which is linked with the ItemID, has a Auto-Increment ID and has a Date (and other columns to capture various things)

Which means, for every Item, I’ll have many ItemStatuses.

Items:

ItemID 
  1
  2

ItemStatuses:

 ID    ItemID    Date
----------------------------
 1       1      1/1/2010...
 2       1      1/2/2010...
 3       1      1/3/2010...
 4       2      1/1/2010...
 5       2      1/2/2010...

I want to be able to join each Item with the latest ItemStatus. I’ve got a solution which grabs the information into entity objects and then does the work, but this takes so much time. If I could query this using LINQ2SQL it would be so much faster. I’ve read several other questions on stackoverflow but none of the examples make sense for my scenario. I’ve tried to figure this out, but still cannot get it to work.

I need this:

 ItemID       Date
-----------------------
    1       1/3/2010...
    2       1/2/2010...

This is a simplistic example. I don’t want just specific columns. There are MANY columns in the Items and ItemStatuses that I need to capture. But the ones mentioned are the control columns.

If someone could give me a hand I would really appreciate it.

The query I have now doesn’t work, but it’s where I’m at right now:

var results = from i in context.Items
              from s in context.ItemStatuses
              where s.ItemID.Equals(i.ItemID) s.Date <= inputDate
              orderby s.Date descending
              select new { i, s };
  • 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-27T14:36:28+00:00Added an answer on May 27, 2026 at 2:36 pm

    The Following query joins the two tables and selects only the ItemStatuses that has the latest Date value:

    var results = from i in context.Items
                  join s in context.ItemStatuses
                         on 
                         new 
                         {
                              ID      = i.ItemID,
                              maxDate = (
                                             from ss in context.ItemStatuses 
                                             where ss.Date <= inputDate
                                             select ss.Date
                                         ).max
                         }
                         equals new
                         { 
                              ID   = s.ItemID,
                              maxDate = s.Date 
                         }
                   select new 
                   {
                       i.ItemID, s.Date
                   };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have table with column 'URL' whrere I store urls like this
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say I'm writing a Windows Forms (.NET Framework 3.5) application which shows the
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say, I've got a XmlNode: <A>1</A> How to remove a text from it,
Let's say I have this MySQL table: OK.. see the type field? Type 0
Let's say I have an image called hello.png with dimensions 200x100 . I create
Let's say I'm making a tool to help epicureans keep track of which delicacies

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.