Question: Hello everyone i have the following row as a sample in my table 

```
id      shop_id     start_time      end_time
1       21          10:00           11:00

```

and i want to check whether start\_time and end\_time exist in table or not 
I am using following query but not working correctly, Where i am wrong ?

```
select * 
  from usr_booking 
 where shop_id='21' 
   and start_time between '10:10:00' and '11:01:00' 
    or end_time   between '10:10:00' and '11:01:00'

```

Answer: 
You need to clearly separate the checks on the `shop_id` and the time ranges:

```
SELECT *
FROM usr_booking
WHERE
    shop_id = 21 AND
    (start_time BETWEEN '10:10:00' AND '11:01:00' OR
     end_time BETWEEN '10:10:00' AND '11:01:00');

```

The `AND` operator in MySQL has higher precedence than the `OR` operator. So, your current query is actually evaluating as this:

```
SELECT *
FROM usr_booking
WHERE
    (shop_id = 21 AND
     start_time BETWEEN '10:10:00' AND '11:01:00') OR
     end_time BETWEEN '10:10:00' AND '11:01:00';

```

Clearly, this is not the same logic as you what you probably intended.
Try to make groups in such type of queries

```
select * from usr_booking where shop_id='21' AND ((start_time between '10:10:00' and '11:01:00') OR (end_time between '10:10:00' and '11:01:00'))

```

Add the extra brackets make groups.