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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:26:48+00:00 2026-06-11T18:26:48+00:00

I have query that is returning the follwing data: Number WeekNumber Date 1111 23

  • 0

I have query that is returning the follwing data:

Number  WeekNumber  Date
1111    23          9/11/12 11:01 AM
1111    23          9/11/12 11:58 AM
2222    24          9/17/12 10:14 AM
2222    24          9/18/12 9:52 AM
2222    24          9/19/12 9:46 AM
2222    24          9/20/12 9:42 AM

However what I want is to get the latest date for each week, the result should be:

Number  WeekNumber  Date
1111    23          9/11/12 11:58 AM
2222    24          9/20/12 9:42 AM

What could I use to obtain this. I have tried to use MAX(DATE) but what I am obtaining is the latest date, not the latest date for each week. I have tried with distinct too but I couldn’t make it work with the WHERE clause.

Thank you very much.

  • 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-11T18:26:49+00:00Added an answer on June 11, 2026 at 6:26 pm

    You say the apparent 1:1 relationship between Number and WeekNumber is an artefact of the data you posted and doesn’t really apply in your actual data. If that is the case a straightforward GROUP BY won’t provide your answer.

    If you are using a flavour of RDBMS which uses analytic functions this will work:

    select distinct number
           , weeknumber
           , max(date) over (partition by weeknumber) as weekly_max_date
    from yourtable;
    

    If you don’t have analytics you will need to use a correlated sub-query:

    select distinct t.number
           , t.weeknumber
           , q.weekly_max_date
    from yourtable t
         join ( select weeknumber, max(date) as weekly_max_date
                from yourtable
                group by weeknumber) q
         on (q.weeknumber = t.weeknumber)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following LINQ expression that's not returning the appropriate response var query
I have a query that is returning in vastly different amounts of time between
I have a simple Nhibernate Linq query that is returning more results than expected:
So I have this awesome MySQL query that's returning me an awesome array >
This query that I have is returning therapists whose 'therapistTable.activated' is equal to false
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,
I've got a mysql query that is returning the required data, but is not
I have a SQL query that is returning a table like the following: id
I have this rather complex query that grabs data from three tables, and now
I have the following SQL query that runs fairly well, however it seems to

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.