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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:38:53+00:00 2026-06-08T12:38:53+00:00

I hope the answer is simple and I’m silly. So I’ve two tables: day

  • 0

I hope the answer is simple and I’m silly.

So I’ve two tables: day (with PK id_day) and hour (with PK id_hour).

I’ve an another table tilt_time which has id_day, id_hour fields and a plus FK field (which has prohibited times). E.g. tilt_time has the following rows (id_day, id_hour, id_target):

1,1,1
1,2,1
1,3,1
1,1,2
1,2,2

In table day id_day is between 1 and 5 (monday to friday) and hour id_hour is between 1 and 6 (so you can imagine a day_hour table with 5*6=30 values).

So I want query id_target=1‘s free periods and id_target=2‘s free periods (everbody’s free periods). So I want similar:

1,4,1
1,5,1
1,6,1
2,*,1
3,*,1
4,*,1
5,*,1
// id_target=2
1,3,2
1,4,2
1,5,2
1,6,2
2,*,2
3,*,2
4,*,2
5,*,2

(* means all valid id_hour values, so every line with * represents 6 different lines)

How can I do this query?

  • 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-08T12:38:56+00:00Added an answer on June 8, 2026 at 12:38 pm

    If you have a target table with all id_target, the answer is simple:

    SELECT 
        d.id_day, h.id_hour, t.id_target
    FROM 
        day AS d
      CROSS JOIN
        hour AS h
      CROSS JOIN
        target AS t
    WHERE
        (d.id_day, h.id_hour, t.id_target) NOT IN
          ( SELECT id_day, id_hour, id_target
            FROM tilt_time
          )
    ;
    

    or the (probably more efficient):

    SELECT 
        d.id_day, h.id_hour, t.id_target
    FROM 
        day AS d
      CROSS JOIN
        hour AS h
      CROSS JOIN
        target AS t
      LEFT JOIN
        tilt_time AS tt
          ON  tt.id         = d.id_day
          AND tt.id_hour    = h.id_hour
          AND t.t.id_target = t.id_target
    WHERE 
        tt.id_target iS NULL ;
    

    If you don’t have a target table, replace the target AS t in the code above with:

    ( SELECT DISTINCT id_target FROM tilt_time ) AS t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope someone has an easy answer on this. I have a header image which
I have an interesting dilemma to which, I hope, someone may have an answer.
i hope there's a simple answer to this. without getting too complicated i have
A minor question that I hope admits of a simple answer that I'll kick
This may have a simple answer (and I hope it does) but looking online
The question is quite simple, and I hope the answer it's simple too :)
Probably a simple answer here, I hope, but seems like a difficult question to
It should be simple, bit I've spent the last hour searching for the answer.
How? Question is simple, hope the answer will be as well.
Its simple question and hope to find quick answer. When I open the application

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.