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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:45:56+00:00 2026-05-12T09:45:56+00:00

I currently have 3 tables, which I’m using for people to make reservations for

  • 0

I currently have 3 tables, which I’m using for people to make reservations for certain pieces of equipment.

Here are my tables:

tblEquipment:
     id        name        description
     1       Camera        Takes pictures
     2       Projector      Projects pictures
     3       Laptop         Portable Computer


tblEvents:
     id        start                 end              first_name         last_name              email
     1     2009-08-10      2009-08-11          John                 Doe                 jd@email.com
     2     2009-08-15      2009-08-16          Jane                 Doe                 jd@email.com


tblEventData:
     id         eventID             equipmentID
     1              1                         1             
     2              1                         2

Right now, a user will submit a query with their requested times, then they will see all available equipment.

So, using the exampe above, if a user is looking for equipment between 8/10-8/11, he will see that the only equipment that is available is: equipmentID 3 (Laptop).

How can I create my query to return only the available equipment based on the requested times?

This is what I’ve come up with so far, but can’t get it to work:

SELECT tblequipment.id as name, tblEvents.start as start, tblEvents.end as end
FROM tblEquipment
INNER JOIN tblEventData on tblEventData.equipmentID = tblEquipment.id
INNER JOIN tblEvents on tbleventdata.eventID = tblEvents.id
WHERE NOT EXISTS(SELECT * FROM tblEvents WHERE $end >= start AND $start <= end)

Any ideas? Thanks!

  • 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-12T09:45:56+00:00Added an answer on May 12, 2026 at 9:45 am

    The query you have now has a NOT EXISTS looking only for events that occur between the start and end times given. In other words, “select all equipment as long as there are no events in this timeframe.” That’s not what you want. You want: “select all equipment as long as there are no events using that equipment in this timeframe.”

    That translates to something like:

    SELECT tblequipment.id as name
    FROM tblEquipment
    WHERE NOT EXISTS 
      (SELECT * FROM tblEvents 
       INNER JOIN tblEventData ON (tblEvents.id = tblEventData.eventID)
       WHERE $end >= start AND $start <= end
       AND tblEventData.equipmentID = tblEquipment.id)
    

    EDIT: I’ve also removed the JOINs from the outer query, since they insist that you select only equipment that’s reserved at some point, which is not at all relevant to the question you’re trying to answer.

    You do want to know what equipment is reserved, but inside the NOT EXISTS query, for the purposes of excluding it from your final results.

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

Sidebar

Related Questions

I have an application in which I'm currently using a two column table in
Greetings, I have some mysql tables that are currently using an md5 hash as
I currently have a message system which writes to two tables, sent and received
I currently have a single DataSet declared which contains 3 tables. For sake of
I currently have two tables in which stores the attendances of a student in
I currently have 2 tables, one is idtracker which has around 30,000 rows and
I currently have multiple tables in my database which consist of the same 'basic
I currently have a fairly long LINQ statement which pulls data from two tables:
I currently have quite a messy query, which joins data from multiple tables involving
We currently have about 30 tables that are using latin1_sweedish_ci for their encodings. I

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.