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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:31:49+00:00 2026-06-13T20:31:49+00:00

Please consider the following table structure (this is sample data, so please ignore the

  • 0

Please consider the following table structure (this is sample data, so please ignore the timestamps being identical):

+---------+---------+------------+-----------+
| list_id | item_id | date_added | is_active |
+---------+---------+------------+-----------+
|    1    |     1   | 1352073600 |     1     |
|    1    |     2   | 1372073600 |     1     |
|    1    |     3   | 1332073600 |     1     |
|    1    |     4   | 1302073600 |     1     |
|    2    |     1   | 1302073600 |     1     |
|    3    |     1   | 1302073600 |     1     |
+---------+---------+------------+-----------+

Our client wishes to show how many lists were created on a certain day. The list is created when the first item is added, but the date is not explicitly stored, only the date the items have been added.

My question is this:

Using MySQL (and PHP for computing the timestamp), how can I return the number of lists that were created on a certain day. Essentially, the logic should be (pseudo-code):

  • select total records from tbl_list_items where date_added >= min_age and date_added <= max_age, and record is oldest for this list

It is difficult to explain what I’m looking for, so consider the following actions:

No items added to lists yet (i.e. all lists have 0 items)
User added `item_id = 1` to `list_id = 1` yesterday.
User added `item_id = 2` to `list_id = 1` today.
User added `item_id = 1` to `list_id = 2` yesterday.
User added `item_id = 1` to `list_id = 3` yesterday.
User added `item_id = 2` to `list_id = 2` today.

If we wanted to look how many lists were created yesterday (or rather, how many lists had the first item added yesterday), I would like to return the total number where the item first added = yesterday. Given the action set above, this would return a total of 3 (i.e. list_id = 1, list_id = 2 and list_id = 3).

  • 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-13T20:31:50+00:00Added an answer on June 13, 2026 at 8:31 pm

    This returns the list of lists created on a specific day:

    SELECT list_id, min(date_added) AS date_creation
    FROM tbl_list_items
    GROUP BY list_id
    HAVING min(date_added) >= @min_age AND min(date_added) <= @max_age
    

    To count them you can count number of results of the query, or use sub-queries like:

    SELECT COUNT(*) AS total FROM
    (
        SELECT list_id, min(date_added) AS date_creation
        FROM tbl_list_items
        GROUP BY list_id
        HAVING min(date_added) >= @min_age AND min(date_added) <= @max_age
    )
    

    However, note that this is totally not-optimized, because you have to GROUP BY the whole table for each query; maybe will be better to add a flag ( creation = 0 | 1 ) when the first item of a list is added.

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

Sidebar

Related Questions

Please consider following sample table structure: +-------------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null |
Please consider the following table structure and data: +--------------------+-------------+ | venue_name | listed_by |
Please consider the following table structure on Oracle: create table DOCS ( DOC_NO NUMBER
Please consider the following tweets table: tweet_id user_id text ---------------------------- 1 1 lorem ipsum
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Please consider the following table (created using a corresponding entity) request ------- id requestor
Please consider the following scripts. Create Table: IF OBJECT_ID('Colortable') IS NOT NULL DROP TABLE
Please consider the following HTML: <td> Some Text <table>.....</table> </td> I need to manipulate
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Please consider the following SQL. I'm trying to create a table that references another.

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.