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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:03:39+00:00 2026-06-03T02:03:39+00:00

I want to order the selected values by ascending distinct date. For example i

  • 0

I want to order the selected values by ascending distinct date.

For example i have these values in my database.

ID | Value | Date 
 1 | 35    | 2012/01/20
 2 | 0     | 2012/01/20
 3 | 10    | 2012/02/01
 4 | 0     | 2012/02/01
 5 | 0     | 2012/03/01
 6 | 0     | 2012/03/01

Since ID 1 has a value on the 20th of January and ID 3 has a value on the 1st of February i want these two dates to be selected to my list of distinct date values. But for ID 5 and 6 both have value 0. So if value is 0 i also want the value 0 to be added.

Now my linqquery looks like this

        var totalHours = (from u in context.Users
                          join r in context.Reports on u.Id equals r.UserId
                          join w in context.Weeks on r.Id equals w.ReportId
                          join d in context.Days on w.DayId equals d.Id
                          orderby d.Date ascending
                          where r.weekNr.Equals(currentWeek)
                          select d.Hour).ToList();

But this query of course gives me 35,0,10,0,0,0 as result.
Though I want it to give me 35,10,0

I dont want do pick out distinct values, say if February 1st and February 2nd has the same values. I want both these values to be added.

  • 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-03T02:03:40+00:00Added an answer on June 3, 2026 at 2:03 am

    I would suggest to first select what you need from the first query:

     var totalHours = (from u in context.Users
                              join r in context.Reports on u.Id equals r.UserId
                              join w in context.Weeks on r.Id equals w.ReportId
                              join d in context.Days on w.DayId equals d.Id
                              orderby d.Date ascending
                              where r.weekNr.Equals(currentWeek)
                              select new {id = r.UserId, hour = d.Hour, date = d.Date}).ToList();
    

    In the above I assumed that d.Hour corresponds to the Value field in your example.

    Then group by date, order by hour descending and select the first item from each group:

    var distinctValues = totalHours
                    .GroupBy(th => th.Date)
                    .OrderByDescending(v => v.Max(o => o.Hour))
                    .Select(g => g.First());
    

    UPDATE

    To return just the list of integers for the Hour property use this instead of the above statement:

     var distinctValues = totalHours
                    .GroupBy(th => th.Date)
                    .OrderByDescending(v => v.Max(o => o.Hour))
                    .Select(g => g.First().Hour)
                    .ToList();
    

    UPDATE 2

    Can you try this ?

    var distinctValues = totalHours
                    .GroupBy(th => th.Date)
                    .Select(g => g.OrderByDescending(e => e.Hour))
                    .Select(g => g.First().Hour)
                    .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to order values from database query by date but I want also
I have a table that has a value field. The records have values somewhat
I want to order a result by fieldx * fieldy , for example: Row
I have a table: ID name c_counts f_counts and I want to order all
If i have a list of numbers: 1,2,3,4,5,6,7,8 and I want to order by
I want to have an 'updateinfo' table in order to record every update/insert/delete operations
I have two combo boxes, one for 'order by' and the other 'direction' (ascending,
I want to insert a value from the database into my dropdown menu in
I have a list box that allows multiple values to be selected. Here is
I have a UISegmentedController to allow a user to choose which order they want

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.