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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:54:36+00:00 2026-05-31T00:54:36+00:00

I am trying to pull off this query without running an inner query, but

  • 0

I am trying to pull off this query without running an inner query, but can’t seem to get the records correctly.

I have two tables (naming convention changed for readability) …

report
    report_id
    name

report_status_log
   report_id
   code
   timestamp

A report can have several status logs. I’m trying to get all reports where the most current report_status_log is equal to a certain code.

This won’t work…

select report.id
       inner join report_status_log on report.report_id = report_status_log.report_id
where  report_status_log.code = 'finished'

… because although ‘finished’ might be in the status logs, it isn’t necessarily always the latest log record.

Is there a way to do this? Or should I be selecting from report_status_log table instead of the report table?

  • 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-31T00:54:38+00:00Added an answer on May 31, 2026 at 12:54 am
    with cte as (
      select *, 
        row_number() over (partition by report_id order by timestamp desc) as RowNum
      from report_status_log
    )
    
    select * 
    from report r
    inner join cte c
    on r.report_id = c.report_id
    where c.code = 'finished' and RowNum = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're trying to pull off this spectaular hack , and have got as far
This sounds dumb, but I can't get it to work. I think i just
As a newbie, I'm trying to pull something off and have gotten stuck. I'm
I'm trying to use a local c# app to pull some images off a
I'm trying to pull in data from a remote SQL Server. I can access
I am trying to pull excerpts and custom fields from specific posts, I have
So I have three tables I am trying to pull data from with the
I'm trying to pull the links off of a bunch of webpages and report
I am trying to pull the top three rows from a database based off
So I've been trying to figure out the most efficient way to pull off

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.