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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:56:33+00:00 2026-06-02T03:56:33+00:00

I have a table Actions , schema blow: [Actions] ActionID Date Status <–Nullable, a

  • 0

I have a table Actions, schema blow:

[Actions]
ActionID
Date
Status <--Nullable, a delta column, only stores value when status changes

Now I want to retrieve the latest record, however it is very likely that Stutus for that record is null, therefore I want to get its last status change(ranked by Date).

Here is an example:

ActionID | Date | Status
------------------------
1        | 04/12| 'Bon'
2        | 04/13| NULL
3        | 04/14| NULL
4        | 04/15| NULL

and my latest record should look like: ActionID: 4, Date: 04/15, Status: 'Bon'

I know it’s possible to do with nested select statements, but in my real table, I have about 10 of these columns, it will drastically affect the performance when a lot of queries like these are made. I wonder if there is a simpler way to do it?

  • 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-02T03:56:34+00:00Added an answer on June 2, 2026 at 3:56 am

    Not sure if I understood your rules, but try this:

    SELECT TOP 1
    ActionID,
    Date,
    (SELECT TOP 1 Status FROM Actions WHERE Status IS NOT NULL ORDER BY ActionID DESC) AS Status
    FROM Actions
    ORDER BY ActionID DESC
    

    You said you have 10 columns.. How it works?

    Like scenario A)

     ActionID | Date  | StatusA | StatusB | StatusC
            1 | 04/11 | DELTA_A | NULL    | DELTA_C
            2 | 04/12 | NULL    | DELTA_B | DELTA_C
            3 | 04/13 | DELTA_A | NULL    | NULL 
    

    ..then multiple SELECT TOP 1 subqueries is still best choise I think..

    but if it’s like scenario B)

     ActionID | Date  | StatusA | StatusB | StatusC
            1 | 04/11 | NULL    | NULL    | NULL
            2 | 04/12 | DELTA_A | DELTA_B | DELTA_C
            3 | 04/13 | NULL    | NULL    | NULL 
    

    ..then you may “reverse” your query like this:

    SELECT TOP 1
    (SELECT TOP 1 ActionID FROM Actions WHERE Status IS NOT NULL ORDER BY ActionID DESC) AS ActionID,
    (SELECT TOP 1 Date FROM Actions WHERE Status IS NOT NULL ORDER BY ActionID DESC) AS Date,
    StatusA,
    StatusB,
    StatusC
    FROM Actions
    WHERE StatusA IS NOT NULL -- then StatusB and StatusC are also NOT NULL
    ORDER BY ActionID DESC
    

    ..but be aware you may get empty result if there is no row with StatusA = NOT NULL.

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

Sidebar

Related Questions

I have an Actions table that records the actions taken by the users: ActionId,
I have a table name Discount that has the following schema: PK DiscountID int
Here is my mysql table scheme; status table // has statusID, userID,date, subject, date
I have a master table people people fields: Id,AlterationDate And an actions table actions
Here's my table schema [dbo].[Action_History]( [ActionID] [int] IDENTITY(1,1) NOT NULL, [objectID] [int] NOT NULL,
I have an SQL table written in MSSQL: create table [action] ( action_id bigint
I have two database tables with the following structure: actions: action_id int(11) primary key
I have this form:- <form action=> <table border=0> <td colspan=2 class=instruction>Select your desired option
i have table structure with 3 colums (column1, column2, column3) and i want to
I have table with 3 columns A B C. I want to select *

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.