简体   繁体   中英

Double AND Where Clause with between Dates

I currently have a query like this

WHERE Category = 'Freezing' OR Category ='Ooredoo FTTH fault'OR Category ='Ooredoo TT fault ' OR Category ='No Picture'

but i want use this date search query with the above code, im able to use any 1 of this code but im unable to use both query, i have used "AND" or "OR" But its Not working,

ScheduleDate BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'  ```

a or b or c and d is ambiguous. You need to use parenthesis to make it explicit how to group the ands and ors. If you want category to match ANY of the options AND the schedule is between certain dates. (a or b or c) and d .

where (
    Category = 'Freezing' or
    Category = 'Ooredoo FTTH fault' or
    Category = 'Ooredoo TT fault ' or
    Category = 'No Picture'
  )
  and ScheduleDate BETWEEN ? AND ?

(Note: Do not use string concatenation to put values into queries, especially not straight from user input. It's a security hole and can cause errors. Usebind parameters .)

(Note: You have an extra space in one of your options.)

You can also use in to make the query simpler.

where
  Category in (
    'Freezing', 'Ooredoo FTTH fault', 'Ooredoo TT fault', 'No Picture'
  )
  and ScheduleDate BETWEEN ? AND ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM