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()
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'))


