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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:14:24+00:00 2026-05-20T11:14:24+00:00

Consider the following: CREATE TABLE Members ( MemberID CHAR(10) , GroupID CHAR(10) , JoinDate

  • 0

Consider the following:

CREATE TABLE Members 
(
    MemberID CHAR(10)
    , GroupID CHAR(10)
    , JoinDate DATETIME
)

INSERT Members VALUES ('1', 'A', 2010-01-01)
INSERT Members VALUES ('1', 'C', 2010-09-05)
INSERT Members VALUES ('1', 'B', 2010-04-15)
INSERT Members VALUES ('1', 'B', 2010-10-10)
INSERT Members VALUES ('1', 'A', 2010-06-01)
INSERT Members VALUES ('1', 'D', 2001-11-30)

What would be the best way to select from this table, determining the implied “LeaveDate”, producing the following data set:

MemberID GroupID JoinDate    LeaveDate
1        A       2010-01-01  2010-04-14
1        B       2010-04-15  2010-05-31
1        A       2010-06-01  2010-09-04
1        C       2010-09-05  2010-10-09
1        B       2010-10-10  2010-11-29
1        D       2010-11-30  NULL

As you can see, a member is assumed to have no lapse in membership. The [LeaveDate] for each member status period is assumed to be the day prior to the next chronological [JoinDate] that can be found for that member in a different group. Of course this is a simplified illustration of my actual problem, which includes a couple more categorization/grouping columns and thousands of different members with [JoinDate] values stored in no particular order.

  • 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-20T11:14:25+00:00Added an answer on May 20, 2026 at 11:14 am

    Something like this perhaps? Self join, and select the minimum joining date that is greater than the joining date for the current row – i.e. the leave date plus one. Subtract one day from it.

    You may need to adjust the date arithmetic for your particular RDBMS.

    SELECT
          m1.*
        , MIN( m2.JoinDate ) - INTERVAL 1 DAY AS LeaveDate
    FROM
        Members m1
    LEFT JOIN
        Members m2
    ON    m2.MemberID = m1.MemberID
    AND   m2.JoinDate > m1.JoinDate
    GROUP BY
          m1.MemberID
        , m1.GroupID
        , m1.JoinDate
    ORDER BY
          m1.MemberID
        , m1.JoinDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Consider the following table which has the fields - id (int) and date_created (datetime):
Consider the following table: create table temp ( name int, a int, b int
Please consider the following scripts. Create Table: IF OBJECT_ID('Colortable') IS NOT NULL DROP TABLE
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Please consider the following SQL. I'm trying to create a table that references another.
Consider the following table: CREATE TABLE `prize` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `prize_details_id`
Consider following logic as requirement: var count=4; for(var i=0;i<count;i++) { /* create a table
Consider the following database schema: create table UserGroup ( id int not null auto_increment,
Consider the following table: create table language ( id integer generated always as identity

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.