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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:10:38+00:00 2026-06-08T03:10:38+00:00

Immediate disclaimer: Its been a few years since I seriously did SQL, returning recently.

  • 0

Immediate disclaimer: Its been a few years since I seriously did SQL, returning recently.

Given a table:

logical_id, instance_id, node_id, state, time_stamp
1, 1, a, starting, 1300003234
2, 1, a, up, 1300003235
**3, 1, b, starting, 1300003237**
4, 1, a, completed, 1300003239
5, 1, a, shutdown, 1300003240

Given a specific instance_id (e.g. 1) I want to get the last state record (single row- highlighted in bold) of the authoritive node, the authoritive node is the most recent one to have entered a ‘starting’, in the absence of any node entering a starting stage it just the most recent node to be logged.

I figured I do some form group by node_id with order by (rather than filter) boolean(state = ‘starting), time_stamp desc, but I cant seem to get this right, in addition I think the group by would have to come after the ordering.

Im using postgres 9.x

  • 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-08T03:10:39+00:00Added an answer on June 8, 2026 at 3:10 am

    This will retrieve the most recent stating node, if it exists, otherwise it will simply return the most recent non-starting node.

    SELECT U.logical_id, U.instance_id, U.node_id, U.state, U.time_stamp
    FROM 
    (
     SELECT M1.logical_id, M1.instance_id, M1.node_id, M1.state, M1.time_stamp, 1 AS node_type
     FROM MyTable M1
     WHERE M1.instance_id=1 AND M1.state='starting' 
     ORDER BY M1.time_stamp DESC LIMIT 1
    
     UNION
    
     SELECT M2.logical_id, M2.instance_id, M2.node_id, M2.state, M2.time_stamp, 0 AS node_type
     FROM MyTable M2
     WHERE M2.instance_id=1 
     ORDER BY M2.time_stamp DESC LIMIT 1
    ) AS U
    ORDER BY U.node_type DESC  LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can i get immediate parent of a given element ? $(e.target).parent() ?
The Disclaimer First of all, I know this question (or close variations) have been
Possible Duplicate: JavaScript: immediate function invocation syntax A similar question has been asked here
I'm trying to get this dynamic SQL running ( using EXECUTE IMMEDIATE ) M_SQL_STATEMENT
In Access 2003 VBA (Used Immediate Window) ? CDate(39870) Returns: 2/26/2009 In SQL Server
I have one question about EXECUTE IMMEDIATE. I have dynamicly changed table name in
An R namespace acts as the immediate environment for all functions in its associated
The Immediate Window is an immensely useful tool for debugging applications. It can be
Why can't an immediate value be moved into a segment registry directly (i.e. mov
I need immediate help. ): and i know little english. ASP.NET MVC 3 Linq

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.