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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:39:30+00:00 2026-05-13T19:39:30+00:00

Here is the data Flag Zone Info Date R North AAA 2010-2-14 R North

  • 0

Here is the data

Flag      Zone         Info         Date
R         North        AAA          2010-2-14
R         North        AAA          2010-2-24
T         North        AAA          2010-2-4
R         South        AAA          2010-2-23
T         South        AAA          2010-2-14
R         EAST         AAA          2010-2-22
T         EAST         AAA          2010-2-11
T         EAST         AAA          2010-2-1
T         EAST         AAA          2010-2-14
R         WEST         AAA          2010-2-29

Here is a table in the SQL SERVER, now I want to get a record from each group based on Zone column. The Flag field of this record should be R, and the Date should be the closest and after today’s date.

Best Regards,

  • 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-05-13T19:39:30+00:00Added an answer on May 13, 2026 at 7:39 pm

    Using ROW_NUMBER you can try

    DECLARE @Table TABLE(
            Flag VARChAR(1),
            Zone VARCHAR(10),
            Info VARCHAR(10),
            Date DATETIME
    )
    
    INSERT INTO @Table SELECT 'R','North','AAA','2010-2-14' 
    INSERT INTO @Table SELECT 'R','North','AAA','2010-2-24' 
    INSERT INTO @Table SELECT 'T','North','AAA','2010-2-4' 
    INSERT INTO @Table SELECT 'R','South','AAA','2010-2-23' 
    INSERT INTO @Table SELECT 'T','South','AAA','2010-2-14' 
    INSERT INTO @Table SELECT 'R','EAST',' AAA','2010-2-22' 
    INSERT INTO @Table SELECT 'T','EAST',' AAA','2010-2-11' 
    INSERT INTO @Table SELECT 'T','EAST',' AAA','2010-2-1' 
    INSERT INTO @Table SELECT 'T','EAST',' AAA','2010-2-14' 
    INSERT INTO @Table SELECT 'R','WEST',' AAA','2010-2-28' 
    
    ;WITH Dates AS(
        SELECT  *,
                ROW_NUMBER() OVER (PARTITION BY Zone ORDER BY Date) ROWID
        FROM    @Table
        WHERE   Flag = 'R'
        AND     Date > GETDATE()
    )
    SELECT  *
    FROM    Dates 
    WHERE   ROWID = 1
    

    If you cannot use ROW_NUMBER you could try

    SELECT  t.*
    FROM    (
                SELECT  Zone,
                        MAX(Date) MaxDate
                FROM    @Table
                WHERE   Flag = 'R'
                AND     Date > GETDATE()
                GROUP BY Zone
            ) Dates INNER JOIN
            @Table t ON Dates.Zone = t.Zone and Dates.MaxDate = t.Date
    

    But this will not exclude duplicates…

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

Sidebar

Related Questions

My html is like this <div id=rsContainer> <table id=rsTable><!-- DATA HERE --></table> </div> and
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
last time I asked how to populate a data structure here . Now I
I asked a question a while back on here regarding caching data for a
I'm downloaded the code from John Papa's book here: http://silverlight-data.com/ and am sucessfully running
I'm having difficulty with pages that does not show the updated data immediately Here's
ex: <a><strike>example data in here</strike></a> I want everything inside the a tag, to the
How can I represent the following in XSD. <price-update> <![CDATA[ arbitrary data goes here
Here is my Json data: [{ok : false, details : [{n : Email, v
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =

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.