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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:18:17+00:00 2026-06-03T17:18:17+00:00

I have four tables: days CREATE TABLE days ( day text priamry key );

  • 0

I have four tables:

days

CREATE TABLE days (
day text priamry key
);

These days run monday to saturday.

times

CREATE TABLE times (
time time Primary Key,
peak text 
);

The time run from 8:00 am to 9:00 pm in hour slots E.g. 8:00, 9:00, 10:00, 11:00

activities

CREATE TABLE activities (
activity text primary key
);

and planner

CREATE TABLE planner (
day text foriegn key references days (day)
time time foriegn key references times (time)
activity text foriegn key references activities (activity)
member bigint
primary key (day, time, member)
);

The planner table will have data like:

friday, 09:00, squash_court1 , 2
friday, 09:00, squash_court2 , 3
friday, 09:00, squash_court3 , 1

What I am wanting to do i make a list of all the none booked times for these three courts
So I would have a list like

time  activity
08:00 squash_court1
10:00 squash_court1
...rest of times...
08:00 squash_court2
10:00 squash_court2
...rest of times...
08:00 squash_court3
10:00 squash_court3
...rest of times...

an the reason these is no 9:00 between 8:00 and 10:00 is because it has been booked

EDIT

At the moment I have the basic join of:

SELECT time , activity FROM times, activities;

All I need now is the WHERE clause to remove the ones that are booked in the planner table.

Thank you for any advice on this matter.

  • 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-03T17:18:19+00:00Added an answer on June 3, 2026 at 5:18 pm

    All I need now is the WHERE clause to remove the ones that are booked in the planner table.

    This can be done in various ways. LEFT JOIN / WHERE .. IS NULL often produces the fastest plan in PostgreSQL:

    SELECT t.time, a.activity
    FROM   (days d CROSS JOIN  times t CROSS JOIN activities a)
    LEFT   JOIN planner p ON (p.day, p.time, p.activity)
                           = (d.day, t.time, a.activity)
    WHERE  p.activity IS NULL;
    

    I use parenthesis to make clear you want to CROSS JOIN (same as a comma between the tables) daysand times and activities first. These parenthesis are redundant, because tables are joined from left to right by default.

    The JOIN condition is just a shorter form of:

     ON p.day = d.day
    AND p.time = t.time
    AND p.activity = a.activity
    

    Another way would be a NOT EXISTS semi-join:

    SELECT t.time, a.activity
    FROM   (days d CROSS JOIN  times t CROSS JOIN activities a)
    WHERE  NOT EXISTS (
       SELECT *
       FROM   planner 
       WHERE (p.day, p.time, p.activity)
           = (d.day, t.time, a.activity)
       );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these four tables: feeds, feed_entries, entries_categorias and categorias. Whith these structures: CREATE
I have four tables each with its own form, all these table share same
i have four tables like below in sql server 2008 : TABLE 1 ->
I have four different tables, one main SPECIAL table containing only id's that reference
I have four tables: characters arena_team arena_table_member arena_team_stats. characters table has guid, name arena_team
I am wanting to have a view table that aggregates rows from four tables.
I have four tables in a MySQL database and I am trying to create
If I have four tables, each with four columns, which use the primary key
I have four tables containing exactly the same columns, and want to create a
Ok, I have four tables: Table 1: f_withholdings Table 2: f_wh_list Table 3: f_rpayments

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.