I am getting challenge with this choose statement:
Select * from table where row != '' and row2 like '%test%' or like '%test2%';
The "or like" part is not working, I am speculating I am utilizing it improperly.
You'd make a move such as this:
SELECT * FROM table WHERE row != '' AND (row2 like '%test%' OR row2 like '%test2%')
Each And / Or work on one factor. As others have noted, order of procedures are essential. You need to group expressions using
() to ensure that they're examined first.
You miss the "row2" in second like, but additionally your query like now works such as this
Select * from table where row != '' and row2 like '%test%'; Select * from table where row2 like '%test2%';
If you want it like this, it's ok, however i presume you would like both in searches the row to become != ""?
If that is the situation, than your query should such as this:
Select * from table where row != '' and (row2 like '%test%' or row2 like '%test2%');
spot the brackets.
There's an operator priority problem - use parentheses to solve it:
SELECT * FROM table WHERE row != '' AND (row2 LIKE '%test%' OR row2 LIKE '%test2%');
You had been also missing the 2nd 'row2' within the OR'd conditions.
Obviously, the 2nd LIKE symptom in the example won't return any rows the first doesn't (because every row that consists of 'test2' also consists of 'test'), but we are able to think that was an over-simplification for that reasons from the question.
Where clauses are connected to posts Of the row inside a table you're querying from, not really a "row" itself. So, if handling a simple customer table, you can apply LIKE queries something similar to
select lastname, firstname, address from customers where firstname like 'Bill%' OR lastname like '%mar%'
will return any names in which the name would particularly Begin with "Bill" no matter what it really finishes with (through the "%" wildcard)
the surname has got the value "marly" any place in the surname, for example "Marcus", "Tamara", "Omar"...
Each "LIKE" clause being applied is dependant on the column you are looking at evaluating against.... Should you wanted multiple values examined for any single column you would need to write it every time...
where firstname like 'Bill%' or firstname like 'John%' or firstname like '%any%'