MySQL select with "between" and "AND"

Fabian Tschullik picture Fabian Tschullik · Mar 1, 2017 · Viewed 7.5k times · Source

i have this part of an sql select:

where `zipCode` between "40000" and "42000"
OR `zipCode` between "50000" and "51000"
OR `zipCode` between "53000" and "60000"
AND plan = "sell" 
AND created_at > '2017-01-01' 
AND clone_id is not null

I'm getting the correct range of the zipCode back. But the condition with "plan" "ceated_at" and "clone_id" is not working.

Answer

Mansoor picture Mansoor · Mar 1, 2017
Try below query :

where ( `zipCode` between "40000" and "42000" OR `zipCode` between "50000" and   
"51000" OR `zipCode` between "53000" and "60000" )
AND plan = "sell" AND created_at > '2017-01-01' AND clone_id is not null