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

  • Home
  • SEARCH
  • 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 77575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:51:07+00:00 2026-05-10T20:51:07+00:00

Could you tell me how to translate the following SQL code to Linq To

  • 0

Could you tell me how to translate the following SQL code to Linq To SQL or Linq To Entites?

The correct SQL code is:

select CollectId,url,userid,pubtime from Collect group by url,collectid,userid,pubtime having pubtime >= (select max(pubtime) from collect d where d.url = collect.url ) order by Collect.pubtime desc

The database table script is:

if exists (select * from sysobjects where id = OBJECT_ID(‘[Collect]’) and OBJECTPROPERTY(id, ‘IsUserTable’) = 1) DROP TABLE [Collect]

CREATE TABLE [Collect] ( [CollectId] [int] IDENTITY (1, 1) NOT NULL, [Url] [nvarchar] (200) NULL, [UserId] [nvarchar] (50) NULL, [PubTime] [datetime] NULL)

ALTER TABLE [Collect] WITH NOCHECK ADD CONSTRAINT [PK_Collect] PRIMARY KEY NONCLUSTERED ( [CollectId] ) SET IDENTITY_INSERT [Collect] ON

INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 1,’www.sohu.com’,’Mike’,’2008-10-10 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 2,’www.echina365.com’,’Lily’,’2008-10-15 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 3,’www.php.com’,’Tom’,’2008-10-20 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 4,’www.echina365.com’,’YaoMing’,’2008-10-23 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 5,’www.echina365.com’,’Mike’,’2008-10-25 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 6,’www.sohu.com’,’Jack’,’2008-10-26 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 7,’www.echina365.com’,’Tracy’,’2008-11-2 0:00:00′) INSERT [Collect] ([CollectId],[Url],[UserId],[PubTime]) VALUES ( 8,’www.php.com’,’YaoMing’,’2008-11-5 0:00:00′)

SET IDENTITY_INSERT [Collect] OFF

  • 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. 2026-05-10T20:51:07+00:00Added an answer on May 10, 2026 at 8:51 pm

    Since your ‘having’ condition isn’t actually on an aggregated column, couldn’t you just use the ‘where’ clause?

    select distinct CollectId, url, userid, pubtime from Collect where pubtime >= (select max(pubtime) from collect d where d.url = collect.url) order by Collect.pubtime desc 

    This gets the same result given the dataset you’ve supplied. The LINQ statement then becomes reasonably simple:

    var rows = (from c in Collect where c.PubTime >= (     from d in Collect     where d.Url == c.Url     select d.PubTime).Max() orderby c.PubTime descending select c).Distinct(); 

    I could be misinterpreting your intent though. Perhaps my version of the query doesn’t do exactly what you want. If so, leave me a comment and I’ll delete the answer so as not to confuse the issue.

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

Sidebar

Related Questions

I've recently written this with help from SO. Now could someone please tell me
Could someone tell me what the units the SetTimeout(int) method in the ICriteria interface
Could someone tell me why the SSRS web service ReportService2005.asmx has a recursive parameter
Could someone tell me how the field Task Group is used in standard SharePoint
Could someone please tell me which objects types can be tested using Regular Expressions
Could some one tell me how to capture SOAP messages passed between the client
Could anyone can tell me where I can find full ASP.NET MVC beta documentation?
Could somebody please tell me what is Memory Page Out Rate. I have seen
From this article. Here's the code: float InvSqrt(float x){ // line 0 float xhalf
I was hoping you could tell me what the advantages and disadvantages of BPMN

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.