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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:08:12+00:00 2026-06-17T15:08:12+00:00

I have the following scenario which can solved on the database level or the

  • 0

I have the following scenario which can solved on the database level or the Linq to EF level:
Here is my view in the database:

id  title   date           weight
==================================
1   t1     2013-01-18       1.5
1   t1     2013-01-17       1.4
1   t1     2013-01-15       1.31
1   t1     2013-01-12       1.22
2   t2     2013-01-19       2.3
2   t2     2013-01-16       2.1
2   t2     2013-01-07       1.81
2   t2     2013-01-19       1.62

What I need as a result is one record from each item (t1 and t2) which is the newest one by date.

So the output will be like this:

id  title   date           weight
==================================
1   t1     2013-01-18       1.5
2   t2     2013-01-19       2.3

As I said above Answers on the database level or the linq level using (Distinct) are both welcomed.

Part of my c# linq:

mylist = (from a in db.myview
join art in db.viewTags on a.id equals art.ArticleID
where (art.TagID == tag.ID)
select a).Distinct().Take(10).ToList();

I need distinct records from myview according to a.id (id field of the view)

Thanks

  • 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-17T15:08:13+00:00Added an answer on June 17, 2026 at 3:08 pm

    EDIT – as per update you want distinct by id

    Full article : DistinctBy in Linq (Find Distinct object by Property)

    Following is part of MoreLINQ library.

    Use DistinctBy function

    public static IEnumerable<TSource> DistinctBy<TSource, TKey>
        (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
    {
        HashSet<TKey> seenKeys = new HashSet<TKey>();
        foreach (TSource element in source)
        {
            if (seenKeys.Add(keySelector(element)))
            {
                yield return element;
            }
        }
    }
    

    So to find the distinct values using just the Id property, you could use:

    mylist = (from a in db.myview
     join art in db.viewTags on a.id equals art.ArticleID
     where (art.TagID == tag.ID)
     select a).DistinctBy(a=>a.Id).Take(10).ToList();
    

    select * from table 
    inner join
    (select max(date) as date,id from table group by id) d 
    on d.id = table.id and d.date= table.date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario: We have stored procedures which compare our developement database
I have the following scenario, using mvc3: I have a database table which holds
I have the following scenario. I have a search page which is split into
I have the following scenario, a Customer who can have bank accounts in several
I have the following scenario: Entities are loaded from the database. One of them
HI, I have the following scenario which I will try to explain as best
Have the following scenario. I have a few form, which essentially have a few
I have following scenario: alt text http://static.zooomr.com/images/7579022_e64808b855_o.png We have a WebService which poses as
I have the following scenario where I have a page say parentPage.html, which contains
I have the following scenario: Two lists of different Types which happen to contain

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.