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

The Archive Base Latest Questions

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

I need to make a graph from a log. The log entries are not

  • 0

I need to make a graph from a log. The log entries are not in regular intervals.

I would like to select rows between dates along with what the values were immediately before the start date (that is, from whenever the immediatly preceeding log was entered).

So, let’s say:

table Foo has id and value columns,

table Bar has id, foo_id, and value columns, and

table BarLog has id, foo_id, bar_id, bar_value and timestamp.

So there can be many Bars for one Foo.

I need all rows from BarLog for all Bars given some foo_id between, say, 07/01/2012 and 07/31/2012 and the value (row) for each Bar as it was on 07/01/2012.

Hope that made sense, if not, I’ll try to clarify.


EDIT (above left for context):

Let’s simplify this down another step. If I have a table with two foreign keys, fk_a and fk_b, and a timestamp, how can I get the most recent rows with a given fk_a and a distict fk_b.

As suggested, here’s an example.

+----+------+------+-------------+
| id | fk_a | fk_b |  timestamp  |
+----+------+------+-------------+
| 1  | 1    | 1    | 01-JUL-2012 |
| 2  | 2    | 2    | 02-JUL-2012 |
| 3  | 1    | 1    | 04-JUL-2012 |
| 4  | 2    | 2    | 05-JUL-2012 |
| 5  | 1    | 3    | 07-JUL-2012 |
+----+------+------+-------------+

Given a fk_a of 1, I would want rows 3 and 5. So looking only at rows 1, 3, and 5 (those with fk_a of 1), get the most recent of each fk_b (where row 3 is more recent than row 1 for fk_b=1).

Thanks again.

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

    Finally found this question which had what I was looking for. Basically just joining with a grouped select. So the answer for my edit would be something like

    SELECT * FROM SomeTable a
    JOIN (
        SELECT fk_b, MAX(timestamp) as latest
        FROM SomeTable
        GROUP BY fk_b
    ) b
    ON a.id = b.id
    WHERE a.fk_a = @someIdA
    

    Which would return the latest of each distinct fk_b with a specified fk_a

    The original question would just be a union of this with a simple get between dates

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

Sidebar

Related Questions

I need to make a duplicate of an existing object graph from one NSManagedObjectContext
i need to take user input and make a very simple bar graph from
From facebook graph api docs this is curl request i need to make. From
I'm trying to make a force directed graph using d3.layout.force , and I need
I need to make a administrative GUI with lots of functionality like lists, forms,
I need to make a moderate system like the one in fmylife.com. Basically the
I need to show values on a horizontal bar like a bar graph. the
I need to develop a graph database in python (I would enjoy if anybody
I would like to create a graph like this one using gnuplot (or matplotlib,
I need to make a Pie Chart and Bar graph using Perl. I need

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.