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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:05:06+00:00 2026-06-02T20:05:06+00:00

I have 8 separate tables. Each table has id, a datetime field and some

  • 0

I have 8 separate tables. Each table has id, a datetime field and some text.

I am presenting data combined from all tables on a single page in a timeline view, most recent entries are at the top, and entries from each table are mixed in this timeline.

Now the hard part – I need to add pagination to this website, so on each page I want to show exactly 10 days (except for the last page, that may have less than 10).
Each table may have variable number of rows.

I’ve been struggling with this for quite some time but have not yet come up with an elegant solution.

Here’s an example (I’ll pick only two tables for this example to make it simpler).

tableA

Apr 1 | a1
Apr 5 | a2
Apr 7 | a3

tableB

Apr 2 | b1
Apr 2 | b2
Apr 5 | b3
Apr 6 | b4

Global timeline would look like this


Apr 7 a3
Apr 6 b4
Apr 5 a2
Apr 5 b3
Apr 2 b2
Apr 2 b1
Apr 1 a1

And if each page shows only 3 days, I need for it to look like this:

— p1 —
Apr 7 a3
Apr 6 b4
Apr 5 a2

— p2 —
Apr 5 b3
Apr 2 b2
Apr 2 b1

— p3 —
Apr 1 a1

The problem is – I can’t figure out a way to query for this data in an elegant way. Here’s some live query that I’ve been messing with:

select date(d.entryTime) entryDate, date(wc.changeTime) wcDate
from diary_entry d
join water_change wc
on d.aquariumId = wc.aquariumId
where d.aquariumId = 2
group by entryDate
order by entryDate
limit 10, 5

so, for one table I have this query:
select date(d.entryTime) entryDate
from diary_entry d
where d.aquariumId = 2
group by entryDate

it yields 13 results
entryDate
2012-01-13
2012-01-14
2012-01-25
2012-01-26
2012-01-31
2012-02-04
2012-02-17
2012-02-20
2012-02-25
2012-03-17
2012-03-31
2012-04-01
2012-04-06

and for another:
select date(wc.changeTime) changeDate
from water_change wc
where wc.aquariumId = 2
group by changeTime

it yields 8 results
2012-01-22
2012-01-26
2012-02-17
2012-02-25
2012-03-04
2012-03-10
2012-04-04
2012-04-24

There are three common days between the two
2012-01-26
2012-02-17
2012-02-25

So the query that I need to produce would have to have
13 + 8 – 3 rows = 18 rows

And solution is found!
(select date(d.entryTime) activityDate
from diary_entry d
where d.aquariumId = 1
group by activityDate)
union
(select date(wc.changeTime) activityDate
from water_change wc
where wc.aquariumId = 1
group by activityDate
order by activityDate)
limit 10, 10

  • 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-02T20:05:07+00:00Added an answer on June 2, 2026 at 8:05 pm

    Query it using a Union.

    SELECT TheDate,
           TheText
      FROM Table_A
     WHERE [your critera]
     UNION
    SELECT TheDate,
           TheText
      FROM Table_B
     WHERE [your critera]
    ...
    

    If you need to only select the distinct ones, you can then wrap this as follows:

    Select Distinct
           TheDate,
           TheText
      From 
    (
     SELECT TheDate,
           TheText
      FROM Table_A
     WHERE [your critera]
     UNION
    SELECT TheDate,
           TheText
      FROM Table_B
     WHERE [your critera]
    ...
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of data which has posts, then I have a separate
I have a data table (dt) that has a datetime column. I also have
I have data spread over two MySQL tables with different structures. One table has
I have bind 2 separate tables using BindingSource. Left grid contains student table and
I have a view table which is a union of two separate tables (say
I have a few SQL Server tables with a datetime field that really only
I have three tables products, sales and costs. The sales and products table each
I have two pieces of data: 1) User and 2) Portfolio. Each user has
I'm building an RSS feed in PHP which uses data from three separate tables.
I have two tables (country & ducks) where the country table has every country

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.