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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:17:33+00:00 2026-05-24T22:17:33+00:00

UPDATED: There can be is_active = true after is_active = false, so I need

  • 0

UPDATED:

There can be is_active = true after is_active = false, so I need to get the last assigned is_active = true and get the preceding is_active = false record

I have a table with this structure

id (not pk but each group is incremental), name, grp, is_active (boolean)

with data like this for group 1

1, name1, group1, true
2, name2, group1, true
3, name3, group1, false
4, name1, group1, false
5, name2, group1, true
6, name3, group1, false <-- this is the next assigned id as the preceding record has an is_active = true
7, (names will differt, group the same and all false)...

… more data in the same table but for group2

100, name1, group1, true
101, name2, group1, true
102, name3, group1, true
103, name1, group1, true
104, name2, group1, true
105, name3, group1, false <-- this is the next assigned id as the preceding record has an is_active = true
106, (names will differt, group the same and all false)...

I have this but it’s not working as I would like it to

SELECT grp, COUNT(*)
FROM tbl_1
WHERE is_active = false
AND id > (
    SELECT id
    FROM tbl_1
    WHERE is_active = true
    ORDER BY id DESC
    LIMIT 1
)
GROUP BY grp

So the return I would like is:

group1, 6
group2, 105

but I get only

group2, 105
  • 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-24T22:17:35+00:00Added an answer on May 24, 2026 at 10:17 pm

    You only really need to find the first id where is_active = false. It is not necessary to apply “greater than first active” condition on id.

    SELECT MIN(id), grp
      FROM tbl_1
      WHERE is_active = false
      GROUP BY grp
    

    UPDATE:

    Answer to the updated question:

    SELECT min(id), grp
      FROM tbl_1 t
      WHERE is_active = false
      AND id > (SELECT max(id) 
                  FROM tbl_1 
                  WHERE is_active = true 
                    AND grp = t.grp)
      GROUP BY grp;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED See post #3 below. There is a need to upload a file to
I have database called Auth, there are fields: id, auth, is_active, created_at, updated_at i
UPDATED: Is there a thread-safe, lock-free and available on all Linux distros increment function
Obviously it gets updated during a write operation, but are there any non-destructive operations
Is there a way to disable Active Record validation for an nhibernate session /
Is there any single msql query which can update customer DOB? I want to
In Rails, you can add a block after a named_scope for additional, context-sensitive methods
I'm a newbie to Nginx, on my VPS, there's no problem to get nginx
In my example code below, you can see that I have been trying to
I have to make a flash game like this: There is a board with

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.