Combine "And" and "OR" Conditions in MySQL (1 Viewer)

TheYoungOne

New member
Local time
Today, 16:28
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 :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:28
Joined
May 7, 2009
Messages
19,169
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%')
 

TheYoungOne

New member
Local time
Today, 16:28
Joined
Dec 12, 2018
Messages
8
Nice, I added those plus some from "Where" Till the end and now it works :)
I'm learning
 

Minty

AWF VIP
Local time
Today, 16:28
Joined
Jul 26, 2013
Messages
10,354
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

Top Bottom