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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:52:23+00:00 2026-05-20T19:52:23+00:00

I have these following two tables: Job Title | PostDate | CompanyId Assitant |

  • 0

I have these following two tables:

Job Title | PostDate | CompanyId
Assitant  | 12/15/10 | 10
Manager   | 12/1/10  | 11
Developer | 12/31/10 | 10
Assitant  | 12/1/10  | 13
PM        | 11/29/10 | 12

CompanyId | Name
10        | Google
11        | Yahoo
12        | Microsoft
13        | Oracle

Now i would like to get 3 different companies with the jobs sorted by post date. The result table would be following:

Job Title | PostDate | CompanyName
Developer | 12/31/10 | Google
Manager   | 12/1/10  | Yahoo
Assitant  | 12/1/10  | Oracle

How can I achieve that using a linq query? Any help will be appreciated…

  • 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-20T19:52:24+00:00Added an answer on May 20, 2026 at 7:52 pm

    I think that would be something like:

    var query = from company in db.Companies
                join job in db.Jobs on company.CompanyId equals job.CompanyId
                group job by company into jobsByCompany
                let lastJob = jobsByCompany.OrderByDescending(x => x.PostDate)
                                           .First()
                orderby lastJob.PostDate descending
                select new
                {
                    JobTitle = lastJob.JobTitle,
                    PostDate = lastJob.PostDate,
                    CompanyName = jobsByCompany.Key.Name
                };
    

    It’s a little odd to do a join and then a group – we could do a GroupJoin instead, but then discard empty options:

    var query = from company in db.Companies
                join job in db.Jobs on company.CompanyId equals job.CompanyId
                     into jobsByCompany // Make this a group join
                let lastJob = jobsByCompany.OrderByDescending(x => x.PostDate)
                                           .FirstOrDefault()
                where lastJob != null
                orderby lastJob.PostDate descending
                select new
                {
                    JobTitle = lastJob.JobTitle,
                    PostDate = lastJob.PostDate,
                    CompanyName = company.Name
                };
    

    EDIT: Note that doesn’t just take the top three results. Use query = query.Take(3); to just get the first three results.

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

Sidebar

Related Questions

i have the following two tables:- GeoShapes GeoShapeId INT IDENTITY Name VARCHAR(100) ShapeFile GEOGRAPHY
I have the following two tables Table: items ID | TITLE 249 | One
I'm having trouble mapping the following in NHibernate: I have two tables (these are
I have two tables, like these: Table People: VARCHAR Name INTEGER Age Table Message
I have these two database tables: locations id name users id location_id last_name first_name
So imagine you have the following two tables: CREATE movies ( id int, name
I have following two arrays. I want the difference between these two arrays. That
I have the following tables, with these keys in my database: bookings session_id sessions
I have 2 tables. The following are just a stripped down version of these
I have two tables (tbArea, tbPost) that relate to the following classes. class Area

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.