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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:04:01+00:00 2026-05-28T15:04:01+00:00

My database (sqlite3), has two tables with the following schemas: CREATE TABLE log(d date,

  • 0

My database (sqlite3), has two tables with the following schemas:

CREATE TABLE log(d date, usr text, tag text, bytes int);
CREATE TABLE valid(tag text, filesize int);

Let’s say I have the following sample data:

      d    | usr  |  tag | bytes
--------------------------------
2012-01-19 | bob  |  foo | 990
2012-01-18 | bob  |  foo | 1000
2012-01-17 | joe  |  bar | 2000
2012-01-16 | joe  |  bar | 1800
2012-01-15 | joe  |  baz | 0


tag  | size
-----------
foo  | 1000
bar  | 2000

I would like to retrieve a list of the most recent events that resulted in a user failing to access all the bytes in a valid file. In the example above, the select should yield 2012-01-19 | bob | foo | 990.

Right now, I’m using two select statements to get the results. The first gets the most recent event per user, and the second checks whether all the bytes were accessed.

CREATE VIEW tmp AS 
SELECT * FROM log JOIN (SELECT max(d) AS maxd, usr FROM log GROUP BY usr) AS 
tmplog ON (tmplog.usr=log.usr and tmplog.maxd=log.d);

SELECT usr,d FROM tmp 
WHERE tag IN (SELECT tag FROM valid) AND bytes NOT IN (SELECT size FROM valid);

Is there a way to do this with one select or more efficiently?

Update:

In the example above, the query shouldn’t retrieve user “joe” since his most recent log entry shows a complete file being accessed.

  • 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-28T15:04:02+00:00Added an answer on May 28, 2026 at 3:04 pm

    Find the most recent d per usr and tag (where bytes < filesize), then select those log entries matching those most recent d/usr/tag values:

        SELECT log.*
          FROM log
    INNER JOIN (    SELECT usr, tag, MAX(d) AS d
                      FROM log
                  GROUP BY 1, 2) most_recent
            ON most_recent.usr = log.usr
                AND
               most_recent.tag = log.tag
                AND
               most_recent.d = log.d
    INNER JOIN valid
            ON log.tag = valid.tag
         WHERE log.bytes < valid.filesize;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation
I have a SQLITE database with two tables. Table A has an integer timestamp
I am using an sqlite database to store log data. My table has a
Background I have an Android project that has a database with two tables: tbl_question
I have a relational database with about 100 tables. Each table has unique, numerical,
I am able to create a connection to a local sqlite3 database ( Using
I'd like to run some ALTER TABLE statements on a sqlite3 database. What happens
I have two tables, Proteins and Species . Protein has Species.Id as foreign key
Let's say I have a database with two tables Persons and PhoneNumbers , where
I am implementing a class that resembles a typical database table: has named columns

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.