Home > Enterprise >  3 or more OR statements are not working in select query in MYSQL
3 or more OR statements are not working in select query in MYSQL

Time:01-12

I have a table named booking. it contains a field Rdate, its date of booking. I want to search the booking table by booking month, booking year, and booking date

SELECT * FROM booking
  where
   oid=1
    and
   ((monthname(`rdate`)='2021-09-16')
    or
   (year(`rdate`)='2021-09-16') or (rdate='2021-09-16')

is not working. The first two or statements are working but the third or statement is not working.

CodePudding user response:

SELECT * FROM `tb1` WHERE (MONTH(date) = 02 OR YEAR(date) = 2009 OR date = '2022-01-09')

Use function MONTH() and YEAR()

Search By DATE enter image description here

Search By YEAR enter image description here

CodePudding user response:

Change the third OR to AND:

SELECT * FROM booking where oid=1 and ((monthname(`rdate`)='2021-09-16') or (year(`rdate`)='2021-09-16') and (rdate='2021-09-16'))
  •  Tags:  
  • Related