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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:18:48+00:00 2026-06-14T17:18:48+00:00

i have the following database table with columns. +—-+———————+———————+——————+ | id | start_datetime |

  • 0

i have the following database table with columns.

+----+---------------------+---------------------+------------------+
| id | start_datetime      | end_datetime        | arena_surface_id |
+----+---------------------+---------------------+------------------+
|  1 | 2012-11-22 02:30:00 | 2012-11-22 05:00:00 |                2 |
|  2 | 2012-11-22 00:00:00 | 2012-11-22 02:30:00 |                2 |
|  3 | 2012-11-22 05:00:00 | 2012-11-22 08:00:00 |                2 |
|  4 | 2012-11-22 08:00:00 | 2012-11-22 11:00:00 |                2 |
|  5 | 2012-11-22 11:00:00 | 2012-11-22 17:00:00 |                2 |
+----+---------------------+---------------------+------------------+

with the user input of date, start time, and end time, i want to find out if there are any slots booked for particular arena_surface_id within the given period of time.

for example if user input is.

start_datetime : 2012-11-22 6:00
end_datetime : 2012-11-22 9:00
arena_surface_id : 2

i want to know if there are any rows which matches time slot between 6:00 and 9:00 for the given date time (in the above example it should match).

what would be the proper mysql query for this?

This is actually a follow up question for this how would I detect a non-overlap of two time periods?

UPDATE

@March this is what it returns when i use your query.

SELECT 
    id, 
    start_datetime, 
    end_datetime, 
    arena_surface_id 
FROM 
    gce_arena_surface_booking 
WHERE 
    (start_datetime BETWEEN '2012-11-22 04:00:00' AND '2012-11-22 09:00:00')
OR 
    (end_datetime BETWEEN '2012-11-22 4:00:00' AND '2012-11-22 9:00:00')


+----+---------------------+---------------------+------------------+
| id | start_datetime      | end_datetime        | arena_surface_id |
+----+---------------------+---------------------+------------------+
|  1 | 2012-11-22 02:30:00 | 2012-11-22 05:00:00 |                2 |
|  3 | 2012-11-22 05:00:00 | 2012-11-22 08:00:00 |                2 |
|  4 | 2012-11-22 08:00:00 | 2012-11-22 11:00:00 |                2 |
+----+---------------------+---------------------+------------------+

the middle record does not match the condition, and still fetches it.

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

    How about

    SELECT * 
    FROM yourTable
    WHERE (startTime BETWEEN 'yourStartImput' AND 'yourEndImput') OR (endTime BETWEEN 'yourStartImput' AND 'yourEndImput')
    

    So you check if there’s a match that starts or ends between your input.

    For your comment, your final query should look like this:

    SELECT * 
    FROM yourTable
    WHERE ((startTime BETWEEN 'yourStartImput' AND 'yourEndImput') 
      OR (endTime BETWEEN 'yourStartImput' AND 'yourEndImput')) 
      AND arena_surface_id = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data in a database table, Columns : Date, Hour(from 1
I have three mysql table from same database Db1. Three tables have following columns.
I have a (mysql) database table with the following columns: NAME | String (Unique)
i have a database table prop_amenities which have following columns here is the create
I have a following details in my database table with columns: currency code currency
I have the following database tables: table: person Columns: id, first_name, age, city, state
I have the following database table object: public class Goal { @DatabaseField(generatedId = true)
Let's say I have the following database table: record_id | record_date | record_value -----------+-------------+--------------
I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,
I have the following database design: Employee Table: Username, Name Quiz Table: QuizID, Title,

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.