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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:08:13+00:00 2026-05-13T23:08:13+00:00

Considering the following table: someId INTEGER #PK ageStart TINYINT(3) ageEnd TINYINT(3) dateBegin INTEGER dateEnd

  • 0

Considering the following table:

someId INTEGER #PK
ageStart TINYINT(3)
ageEnd TINYINT(3)
dateBegin INTEGER
dateEnd INTEGER

Where dateBegin and dateEnd are dates represented as days since 1800-12-28…

And considering some sample data:

someId | ageStart | ageEnd | dateStart | dateEnd
------------------------------------------------
   203 |       16 |     25 |     76533 |   76539   \
   506 |       16 |     25 |     76540 |   76546    adjacent rows
   384 |       16 |     25 |     76547 |   76553   /
   342 |       16 |     25 |     76563 |   76569   \
   545 |       16 |     25 |     76570 |   76576    adjacent rows
   764 |       16 |     25 |     76577 |   76583   /

(There would be arbitrary rows mixed in off course, I just want to illustrate 2 relevant rowsets)

Is it possible to find adjacent rows for a given age category (ageStart to ageEnd) without a stored procedure? The criteria for adjacency is: dateStart is 1 day after dateEnd of the previous found row.

For instance, given the above sample data, if I were to query it with the following parameters:

ageStart = 16
ageEnd = 25
dateStart = 76533

I would like it to return me the rows 1, 2 and 3 of the sample data, since their dates are adjacent (dayStart is next day of previous row’s dateEnd).

ageStart = 16
ageEnd = 25
dateStart = 76563

…would give me rows 4, 5 and 6 of the sample data

  • 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-13T23:08:14+00:00Added an answer on May 13, 2026 at 11:08 pm

    Probably not efficient if lots of data into your table but try this:

    SELECT b.*
    FROM
    (SELECT @continue:=2) init,
    (
     SELECT * 
     FROM ageTable 
     WHERE ageStart=16 AND 
           ageEnd=25   AND 
           dateStart=76533
    ) a 
      INNER JOIN (
       SELECT *
       FROM ageTable
       ORDER BY dateStart
      ) b ON (
        b.ageStart=a.ageStart AND
        b.ageEnd=a.ageEnd     AND
        b.dateStart>=a.dateStart
      ) 
      LEFT JOIN ageTable c ON (
        c.dateStart=b.dateEnd+1 AND
        c.ageStart=b.ageStart   AND 
        c.ageEnd=b.ageEnd
      )
    WHERE 
     CASE
      WHEN @continue=2 THEN
       CASE
        WHEN c.someId IS NULL THEN
         @continue:=1
        ELSE
         @continue
       END
      WHEN @continue=1 THEN
       @continue:=0
      ELSE
       @continue
     END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 323k
  • Answers 323k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To get the number of people who scored better than… May 14, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer Here's an example I've done recently: private UITextField _textField; public… May 14, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer This StackOverflow Question is a good one to start with… May 14, 2026 at 12:57 am

Related Questions

I'm considering the following database structure but I'm not sure what type of Rails
I have four DB tables in an Oracle database that need to be rewritten/refreshed
Rather than use an ORM, I am considering the following approach in Python and
I have a grails app with a domain Restaurant and a domain Person. class
There are a few should I chose this or that questions on SO and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.