-1

I have table "merchant_slots", And i want to check whether "user" with same "day"(1=monday,2=tuesday... and so on) with "same slot" exist or not,Query is working but something wrong with "AND" "OR" operators,whenever i try with different "day" column(2) then showing resuult, should be empty as response,Here is my table "merchant_slots"

id      day     merchantId                  start_time          end_time                
1       1           14955                   12:00               15:00
2       1           14955                   10:00               11:00
3       1           14955                   08:00               09:00

I tried with following code but not working,Where i am wrong ?

SELECT * 
FROM  merchant_slots 
WHERE merchantId='14955'
AND day='2'
AND merchant_slots.start_time BETWEEN '10:00' AND '14:00'
OR merchant_slots.end_time BETWEEN '10:00' AND '14:00'
Ritika
  • 64
  • 5

1 Answers1

0

Perhaps add parentheses to indicate precedence of AND and OR conditions:

SELECT * 
FROM  merchant_slots 
WHERE merchantId='14955'
AND day='2'
AND (merchant_slots.start_time BETWEEN '10:00' AND '14:00'
OR merchant_slots.end_time BETWEEN '10:00' AND '14:00')
Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37