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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:21:58+00:00 2026-05-17T01:21:58+00:00

I have a Parent/Child Table relationship with the ChildTable linking back to the ParentTable

  • 0

I have a Parent/Child Table relationship with the ChildTable linking back to the ParentTable via the ParentId foreign key. There’s multiple records in the ChildTable for each ParentTable record. For those of use you like rudimentary visuals, here’s the diagram.

ParentTable
------------
+Id
Date

ChildTable
------------
+Id
ParentId
Date

What I’m trying to do is return only ONE record for each ParentTable item that’s joined to the most recent ChildTable’s date value (Note, not the Parent’s Date value). The results would look like:

ParentTable::Id ParentTable::Foo ChildTable:Id ChildData::Foo ChildData::Date
--------------- ---------------- ------------- -------------- ---------------
55              Other Values     700           Other values   12/1/2010      
1               "                1000          "              11/30/2010
10              "                214           "              10/31/2010

It’s important that the ChildData::Date is sorted descending.

This seems like it should be simple, but I’m struggling with the LinQ2SQL aspects of it. I’m still waiting for my “ah-ha” moment when I can think in Linq.

Here’s the final answer, thanks to Winston:

var results = 
    from p in parent
    join c in (from c2 in child orderby c2.Date descending select c2)
    on p.Id equals c.ParentId into childGroup
    select new { ParentId=p.Id, ParentDate=p.Date, ChildDate=childGroup.First().Date } into NewResult
    orderby NewResult.Activity descending
    select NewResult
  • 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-17T01:21:58+00:00Added an answer on May 17, 2026 at 1:21 am

    The following should work, I’ve tested it on some dummy data.

    var results = 
        from p in parent
        join c in (from c2 in child orderby c2.Date descending select c2)
        on p.Id equals c.ParentId into childGroup
        select new { ParentId=p.Id, ParentDate=p.Date, ChildDate=childGroup.First().Date };
    

    Updated to select only the fields required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have db table with parent child relationship as: NodeId NodeName ParentId ------------------------------ 1
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have a parent child table relationship. In the example below Foo has a
I have the following table relationship in my database: Parent / \ Child1 Child2
I have a LINQ-to-SQL DataContext that represents a parent-child relationship of Products to Prices.
I have a large result set assembled in a parent/child relationship. I need to
I have parent child relationship between two entities(Parent and Child). My Parent mapping is
When you have parent-child tables and you wish to use a DetailsView to edit
Lets say I have two tables - child and parent with many-to-one relation. What
I have written some CSS which targets elements using the parent > child selector.

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.