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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:45:16+00:00 2026-06-11T04:45:16+00:00

I tried to find answer for my problem, but I couldn’t. I have table

  • 0

I tried to find answer for my problem, but I couldn’t.
I have table with ID, WorkerID, Function(int), and DateTime. Each worker has multiple records for each day. I need to get only first record for each day, for all workers.
This query gives the results I wanted:

SELECT WorkerID, MIN(DateTime) AS DateTime
FROM Records
GROUP BY WorkerID, LEFT(DateTime, 10)   
ORDER BY WorkerID

But I want to select all columns (ID, WorkerID, Function, and DateTime). How can I do that?
Also, I need this query for ASP.NET MVC3 application, so if anyone could write this for me in LINQ, and explain how to transform that query into IEnumerable(Record) or IQuerible(Record), I would be very thankful.
Thanks in advance guys, hope you can save me.

Edit: Your LINQ query worked, but I had a lot of issues regarding perfomance, because of using a lot of Views, not Tables. Now I switched to Table, and I want do query directly on Table. Structure is the same, just instead of WorkerID, I have ETAG, which is the same. But I have problem now. SQL query mentioned above, gives me about 50k results on table, which is correct, but now your LINQ query gives me only 9k, so something is wrong. Here is query:

from d in Records
group d by new { d.ETAG, Date = d.DateTime.Value.Year + d.DateTime.Value.Month +            d.DateTime.Value.Day } into g
orderby g.Key.ETAG
select g.OrderBy(e => e.DateTime).FirstOrDefault()

Please, can you help me with this one…

  • 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-11T04:45:18+00:00Added an answer on June 11, 2026 at 4:45 am
    from r in Records
    group r by new { WorkerId = r.WorkerId, Date = r.DateTime.Value.Date } into g
    orderby g.Key.WorkerId
    select g.OrderBy(e => e.DateTime).First()
    

    Update: added orderby clause, and use g.OrderBy() to enforce selecting the first record for each day, rather than an arbitrary element in the group.

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

Sidebar

Related Questions

Tried searching the site, but cannot find an answer to my problem: Lets say
I tried to search SO but couldn't find close answers. What I have is
I have tried looking for answer in the forum but couldnt find any which
I searched everywhere but I couldn't find an answer for my problem. I play
I have been looking around for an answer to this, but couldn't really find
This may be a very simple problem, but I couldn't find an answer googleing
I've searched the internet thoroughly but couldn't find a clear answer to the problem.
I have been looking around for this but couldn't find an answer anywhere, so
It must be simple, but surprisingly I couldn't find an answer to this problem
tried to find the answer by googling and in MSDN but with no luck.

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.