I'm trying to write a query with LIKE and != conditions:
SELECT *
FROM posts
WHERE title LIKE 'term%'
OR NAME LIKE 'term%'
AND post_type != 'type';
However, the query results are not being filtered by post_type. Is there something wrong with my syntax?
You probably need parenthesis because AND
has operator precedence.
SELECT *
FROM posts
WHERE ( title LIKE 'term%' OR NAME LIKE 'term%' )
AND post_type != 'type';
Because right now without parenthesis you have
SELECT *
FROM posts
WHERE title LIKE 'term%'
OR ( NAME LIKE 'term%'
AND post_type != 'type' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With