Bergum
Bergum

Reputation: 77

How to use LIKE and OR in the same query

I would like to pull out 3 types of data registred in one day. I want to extract every row where toll, park or expence has been recorded.

I can get this to work:

$sqlq = "Select * from mydata WHERE logdate LIKE '$myDato' AND park<>'' ";

But how do i exted it to this:

$sqlq = "Select * from mydata WHERE logdate LIKE '$myDato' AND toll <>'' OR park <>'' OR expence <>'' ";

Upvotes: 2

Views: 37

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

The AND operator takes precedence over the OR operator. In your case you want the presence of multiple OR clauses to do this you need parentheses to change the evaluation rules based on the precedence of the logical operators

So you should use ( and ):

$sqlq = "Select * 
    from mydata 
    WHERE logdate LIKE '$myDato' AND ( toll <>'' OR park <>'' OR expence <>'') ";

Upvotes: 4

Related Questions