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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:27:27+00:00 2026-06-18T10:27:27+00:00

Ladies and Gents, I need to write a query that grabs data from a

  • 0

Ladies and Gents,

I need to write a query that grabs data from a view, but I’m not sure how to go about this. The issue is there is really no key and there are two fields I’m concerned with that will control what rows I need to retrieve.

The view looks something like this:

Category   columna   columnb   uploaddate 
-----------------------------------------------------
   a        value     value    1/30/2013 04:04:04:000 
   a        value     value    1/29/2013 04:04:04:000 
   b        value     value    1/28/2013 01:23:04:000 
   b        value     value    1/30/2013 04:04:04:000 
   b        value     value    1/30/2013 04:04:04:000 
   c        value     value    1/30/2013 01:01:01:000 
   c        value     value    1/30/2013 01:01:01:000 

What I need to retrieve is all rows for each unique category and the newest uploaddate. So in the example above I would get 1 row for category a which would have the newest uploaddate. Category b would have 2 rows which have the 1/30/2013 date. Category c would have two rows also.

I also need to just compare the date of upload, not the time. As the loading can take a couple seconds. I was trying to use max date but it would only grab the time to the second.

Any guidance/thoughts would be great.

Thanks!

EDIT:

Here is what I threw together so far and I think it’s close but it’s not working yet and I doubt this is the most efficient way to do this.

select 
    * 
from 
    VIEW c 
    INNER JOIN 
    ( 
        SELECT 
            Category, 
            MAX(CONVERT(DateTime, Convert(VarChar, UploadDate, 101))) as maxuploaddate  
        FROM 
            View 
        GROUP BY 
            Category, 
            UploadDate 
    ) temp ON temp.Category = c.Category AND CONVERT(VarChar, UploadDate, 101) = temp.maxuploaddate 

The problem lies in the nested selected statement as it’s still grabbing all combinations of Category and Upload date. Is there a way to do a distinct on the Category and UploadDate, just getting the newest combination?

Thanks Again

  • 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-18T10:27:28+00:00Added an answer on June 18, 2026 at 10:27 am

    Your query is close, you have a mistake in the group by. I’d also get rid of the date conversions; date comparisons work fine.

    select 
        * 
    from 
        VIEW c 
        INNER JOIN 
        ( 
            SELECT 
                Category, 
                MAX(UploadDate) as maxuploaddate  
            FROM 
                View 
            GROUP BY 
                Category
        ) temp ON temp.Category = c.Category AND UploadDate = temp.maxuploaddate 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ladies and Gents, I have a very simple grails app from which I need
Good afternoon ladies and gents. So, it is not my day for errors. Implementing
This question is not so much about finding a solution as about getting an
OK Ladies and Gents, I would really appreciate some help: This is my table:
Ladies, gentlemen. I was reading Google's documentation for Closure Templates. There's not that much
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Good evening ladies and gentlemen, I have a problem with Java Swing that I
Hello ladies and gents, I'm having a bit of problem with accept() . I
Ladies and gents, I have a CRM page which references 3 js files, (1x
Need advise I am currently using CRM4.0 webservice to create account from reading my

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.