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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:50:31+00:00 2026-06-14T19:50:31+00:00

i have this mysql table with following records. table name : gce_arena_surface_booking +—-+———————+———————+——————+ |

  • 0

i have this mysql table with following records.

table name : gce_arena_surface_booking

+----+---------------------+---------------------+------------------+
| 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 |
|  6 | 2012-11-22 17:30:00 | 2012-11-22 22:00:00 |                2 |
|  7 | 2012-11-23 02:00:00 | 2012-11-23 18:00:00 |                2 |
+----+---------------------+---------------------+------------------+

i need to know by given date time, if any booking already exist, i am using this query to check if any booking exist for given start_datetime, and end_datetime

SELECT 
    id, start_datetime, end_datetime, arena_surface_id 
FROM 
    gce_arena_surface_booking 
WHERE (
    (start_datetime BETWEEN '2012-11-23 2:00' AND '2012-11-23 6:00') OR 
    (end_datetime BETWEEN '2012-11-23 2:00' AND '2012-11-23 6:00')
) 
AND arena_surface_id = 2

the above query is giving me problems for example if i have the value changed from :

'2012-11-23 2:00' AND '2012-11-23 6:00'

to

'2012-11-23 2:30' AND '2012-11-23 6:00'

note that i have changed the value from 2:00 to 2:30, it does not return me any result if i do that, whereas with reference to above records i expect it to return me a row with id 7 since i have the time slot booked in between 2:00 and and 18:00, and hence any given value that matches time between 02:00 and 18:00 should be returning a row.

what would be the proper mysql query to deal with my problem?

here is the link to sqlfiddle if you want to play around with records and schema.

  • 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-14T19:50:32+00:00Added an answer on June 14, 2026 at 7:50 pm

    The bookings that starts when or after your new booking ends, or that ends when or before your new booking starts are no problem.

    Thus the bookings you need to find are the ones that both starts before your new booking ends, and ends after your new booking starts.

    Your query shoud then be

    SELECT id, start_datetime, end_datetime, arena_surface_id 
    FROM gce_arena_surface_booking 
    WHERE ('2012-11-23 6:00' > start_datetime)
    AND ('2012-11-23 2:00' < end_datetime)
    AND arena_surface_id = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table structured somewhat like this: type name value ===================== 1
I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
I have two mysql tables that have the following structure: Table 1: ---ID---------NAME------- ---1-----
I have following db structure in mysql. Table: Story Id Name categoryid date 1
I have this mysql table called comments which looks like this: commentID parentID type
I have this in a MySQL db: table Message sender_id int recipient_id int created
I have a mysql table that looks like this: id col2 col3 col4 1
I have a MySQL table like this: Payments +----+---------------------+---------+ | id | date (sorted
I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field
I have a MySQL table that looks like this: `id` int(10) unsigned NOT NULL

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.