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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:32:43+00:00 2026-05-23T23:32:43+00:00

I have 2 tables that manages the time spent on doing various things: @times(id,

  • 0

I have 2 tables that manages the time spent on doing various things:

@times(id, time_in_minutes)
@times_intervals(id, times_id, time_in_minutes, start, end)

Then the @times might relate to different things:

@tasks(id, description)
@products(id, description, serial_number, year)

What is the best practice in order to reuse the same @times and @times_intervals for @task and @products?

I would think about:

@times(+task_id, +product_id) 
// add task_id and product_id to the original @times table

But if I do so, when I’d join the @times table with @task and @products table would be slower as should choice between the 2 (task_id or product_id). When task_id is not null join on the @tasks and viceversa.

(I’m using MySQL6)

Thanks a lot

  • 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-23T23:32:44+00:00Added an answer on May 23, 2026 at 11:32 pm

    I would drop the time_in_minutes column from the times table. This information is redundant if it is just the sum of the detail and is a premature optimization.

    I would add a product_time table containing product_id, times_id and a task_time table containing task_id, time_id

    Then to get the total time with a product:

    SELECT *
    FROM product p
    INNER JOIN product_time pt
        ON pt.product_id = p.id
    INNER JOIN (
        SELECT times_id, SUM(time_in_minutes) as time_in_minutes
        FROM times_intervals
        GROUP BY times_id
    ) AS t
        ON t.times_id = pt.times_id
    

    Typically to make this perform, you would have a non-clustered covering index for times_intervals with columns times_id and time_in_minutes – note that the times table is simply a data-less header table at this point and the only purpose it to group the times_intervals and it’s only necessary because you have this very similar arrangement for tasks.

    If there were not two (or more) entities using the times_intervals, you might simply put product_id in the times_intervals and treat it as your header/master id.

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

Sidebar

Related Questions

I have two tables that link together through an id one is submit_moderate and
I have some tables that I'm joining in a query with Postgres (9). However,
I have two tables that have virtually identical content and very similar structure. They
I have two tables that I want to join together. Table1 Year, ID, Theme,
I have 2 tables that I am working with that use the same column;
I have several tables that I am selecting data from. I am trying to
I have many tables that use Lookup/Enum references for most of their column values.
I have some tables that benefit from many-to-many tables. For example the team table.
I have two tables that should be joined together by a foreign key relationship,
I have two tables that were built for two disparate systems. I have records

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.