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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:33:59+00:00 2026-06-02T07:33:59+00:00

I have three tables: CREATE TABLE activities ( activity varchar(20) Primary key ); with

  • 0

I have three tables:

CREATE TABLE activities (
activity varchar(20) Primary key
);

with data:

Table_Tennis1
Table_Tennis2
Table_Tennis3

and

CREATE TABLE times (
time varchar(5)
);

with data

09:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00

and finally

CREATE TABLE planner (
day varchar(9) foreign key
time varchar(5) foreign key
activity varchar(20) foreign key
member bigint foreign key
);

and Primary Key = (day, time, activity)

with data

friday,09:00,Table_Tennis1,4
friday,10:00,Table_Tennis2,2

I was wondering it was possible to find out all the Table_Tennis rooms that are not being used at a certain time on a certain day, or all rooms that have not yet been booked on all times for one day.

so it should give me a result_set of

09:00, Table_Tennis2, Table_Tennis3
10:00, Table_Tennis1, Table_Tennis3
11:00, Table_Tennis1, Table_Tennis2, Table_Tennis3 ect ect
  • 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-02T07:34:01+00:00Added an answer on June 2, 2026 at 7:34 am

    all the Table_Tennis rooms that are not being used at a certain time
    on a certain day,

    SELECT activity
    FROM   activities a
    WHERE  NOT EXISTS (
        SELECT *
        FROM   planner p
        WHERE  p.activity ~~ 'Table_Tennis%' -- may or may not be needed
        AND    p.day  = 'friday'
        AND    p.time = '09:00'
        AND    p.activity = a.activity -- was missing in my 1st draft
        );
    

    all rooms that have not yet been booked on all times for one day.

    SELECT a.activity
    FROM   activities a
    LEFT JOIN (
        SELECT activity
        FROM   planner p
        WHERE  day = 'friday'
        GROUP  BY 1
        HAVING count(*) = 12 -- assuming there are exactly 12 slots
        ) p USING (activity)
    WHERE p.activity IS NULL; -- excludes all fully booked rooms
    

    Or:

    SELECT activity
    FROM   activities a
    WHERE NOT EXISTS (
        SELECT activity
        FROM   planner p
        WHERE  day = 'friday'
        GROUP  BY 1
        HAVING count(*) = 12 -- assuming there are exactly 12 slots
        );
    

    But not:

    
    SELECT activity
    FROM   activities a
    JOIN (
        SELECT activity
        FROM   planner p
        WHERE  day = 'friday'
        GROUP BY 1
        HAVING count(*) < 12
        ) p USING (activity);
    
    

    … because that would drop rooms with no entries for the day at all.


    You might consider using

    slot time
    

    instead of

    time varchar(5)
    

    time should not be used as identifier. It is a reserved word in all SQL standards and a type name in PostgreSQL.
    Also, the data type time is a better fit for your purpose and occupies less space than varchar(5).

    And

     day date foreign key ...
    ,slot time foreign key ...
    

    instead of

     day varchar(9) foreign key ...
    ,time varchar(5) foreign key ...
    

    The names of weekdays would let you cover one week. I assume you want more than that.

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

Sidebar

Related Questions

I've got three tables: CREATE TABLE credential_types ( id serial PRIMARY KEY, name varchar(32)
I have three tables. The designs were like student table create table student (studID
So I have three tables: CREATE TABLE tblUser ( [pkUserID] [int] IDENTITY(1,1) NOT NULL,
I have three tables...users, user_info, and quota_levels. They look like this: CREATE TABLE users
I have three tables: CREATE TABLE person (id int, name char(50)) CREATE TABLE eventtype
I have three tables CREATE TABLE IF NOT EXISTS `tbl_hotelinfo` ( `hotel_id` int(11) NOT
I have four tables: days CREATE TABLE days ( day text priamry key );
I have three tables, a user-table and two user-type tables. The user-type tables have
I have three tables as follows: table 1 is called Cat1, table 2 is
I have three tables: page, attachment, page-attachment I have data like this: page ID

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.