Combine "And" and "OR" Conditions in MySQL

TheYoungOne

New member
Local time
Today, 11:51
Joined
Dec 12, 2018
Messages
8
hello,

I need to combine several "And" and "OR" conditions but can't seem to make it work.

Conditions should be as followed:
All 'PCK' on the 17th of December picked by either a DW, a RT or an OP

What I have now doesn't consider the date constraint, so I'm guessing I'm missing some brackets? :confused:

Code:
	from PRODUCT_HISTORY            
                where                PTH_Type like 'PCK' 
		and                   CONVERT (date, PTH_GenDate) like '2018-12-17'
                and		        REST_Id like 'DOUBLE WALKY%'
	        or		        REST_Id like  'REACH TRUCK%'
		or			REST_Id like 'ORDER PICKER%'

Thanks :)
 
try adding bracket like:
Code:
	from PRODUCT_HISTORY            
                where                PTH_Type like 'PCK' 
		and                   CONVERT (date, PTH_GenDate) like '2018-12-17'
                and		       (REST_Id like 'DOUBLE WALKY%'
	        or		        REST_Id like  'REACH TRUCK%'
		or			REST_Id like 'ORDER PICKER%')
 
Nice, I added those plus some from "Where" Till the end and now it works :)
I'm learning
 
Purley on a semantic point the use of the Like is redundant when there are no wildcards used so you should use =

Code:
 where PTH_Type [COLOR="Red"]= [/COLOR]'PCK' 
and                   CONVERT (date, PTH_GenDate) [COLOR="red"]= [/COLOR]'2018-12-17' ...
 

Users who are viewing this thread

Back
Top Bottom