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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:25:33+00:00 2026-05-15T15:25:33+00:00

I have two tables, timetable and lesson_booking these are linked via timetable_id . timetable

  • 0

I have two tables, timetable and lesson_booking these are linked via timetable_id.

timetable represents timetable entries for a given day (mon, tue etc) that can be selected and used to make a booking for a client in lesson_booking

What I would like to do is get a list of timetable entries that have no bookings associated with it.( i.e. find empty timtables slots)

I can do this but my problem is with doing it for a certain date. I am having some trouble with this as the date is in the lesson_booking table and the entries I am requesting have no link to lesson_booking

Here is what I have so far:
The following will return all empty timetable entries. I want to do it for a specified date only.

I have a feeling that I need to modify the left join but i’m unsure how.

    SELECT 
        lesson_booking.booking_date,
        employee.employee_firstname, employee_lastname,
        TIME_FORMAT(start_time, '%l:%i %p') AS start_time,
        TIME_FORMAT(end_time, '%l:%i %p') AS end_time,
        lesson_type.lesson_type_name

FROM timetable
        LEFT JOIN lesson_booking ON lesson_booking.timetable_id = timetable.timetable_id
        JOIN employee ON timetable.employee_id = employee.employee_id
        JOIN lesson_type ON timetable.lesson_type_id = lesson_type.lesson_type_id
        JOIN day_name ON day_name.day_name_id = timetable.day_name_id
WHERE   ISNULL(lesson_booking_id)
    AND
    day_name = DATE_FORMAT('2010-7-5', '%W')

NOTE: there are other tables linked for employee, lesson type etc. Also, day_name is a table for days i.e monday,tuesday, wednesday etc. The where clause narows to display only timteable entries of a specified day.

Any help is greatly appreciated..

Thanks.

UPDATE:

Note: Here are twi queries. The first contains all the information I want but some extra too.. The second contains the information that I want exluded from the first. How do I combine the two to get just the data I want? Thanks.

    SELECT
    timetable.*
FROM
    timetable
    JOIN day_name ON day_name.day_name_id = timetable.day_name_id
WHERE
    day_name = DATE_FORMAT('2010-7-5', '%W');

-- exclude the following result from the above result.
SELECT
    timetable.*
FROM
    lesson_booking
    JOIN timetable ON timetable.timetable_id = lesson_booking.timetable_id
WHERE
    booking_date = '2010-07-05';

definitions for lesson_booking and timetable

    /*
SQLyog Community- MySQL GUI v8.22 
MySQL - 5.1.30-community-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `COLUMNS` (
    `Field` varchar (192),
    `Type` blob ,
    `Null` varchar (9),
    `Key` varchar (9),
    `Default` blob ,
    `Extra` varchar (81)
); 
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('lesson_booking_id','int(11)','NO','PRI',NULL,'auto_increment');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('client_id','int(11)','NO','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('timetable_id','int(11)','NO','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('horse_owned_id','int(11)','NO','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('transaction_id','int(11)','YES','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('booking_date','date','NO','',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('cancelled_status','int(11)','YES','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('no_show','tinyint(1)','NO','','0','');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('same_time_next_week_booking_id','int(11)','YES','MUL',NULL,'');

/*
SQLyog Community- MySQL GUI v8.22 
MySQL - 5.1.30-community-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `COLUMNS` (
    `Field` varchar (192),
    `Type` blob ,
    `Null` varchar (9),
    `Key` varchar (9),
    `Default` blob ,
    `Extra` varchar (81)
); 
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('timetable_id','int(11)','NO','PRI',NULL,'auto_increment');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('day_name_id','int(11)','NO','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('start_time','time','NO','',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('end_time','time','NO','',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('lesson_type_id','int(11)','NO','MUL',NULL,'');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('employee_id','int(11)','NO','MUL','0','');
insert into `COLUMNS` (`Field`, `Type`, `Null`, `Key`, `Default`, `Extra`) values('timetable_active_status','tinyint(1)','NO','','1','');
  • 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-15T15:25:34+00:00Added an answer on May 15, 2026 at 3:25 pm

    Use:

       SELECT tt.*
         FROM TIMETABLE tt
         JOIN day_name dn ON dn.day_name_id = ttt.day_name_id
                         AND dn.day_name = DATE_FORMAT('2010-7-5', '%W');
    LEFT JOIN LESSON_BOOKING lb ON lb.timetable_id = tt.timetable_id
                               AND lb.booking_date = '2010-07-05'
        WHERE lb.lesson_booking_id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have two tables in my database, table1 and table2. They are identical. But
I have two tables in a legacy database... tblParentTable (int id, string specialIdentifier, ...)
I have two tables A & B, and B has a many:1 relationship with
I have two tables, one parent Point and one child PointValue, connected by a
I have two tables that I want to join into one table and use
I have two tables as follows PRODUCT table Id | Name | Price And
I am making an iPad app, it currently has multiple UITableViews named like so:
I'm trying to use CROSS APPLY in SQL, but only want to use the

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.