I am trying to do a query with multiple conditions. and two of them are linked, at the moment I have put it without parentheses and it works but I don't know if it will give me an error in the future because it doesn't mean the same thing.
the query in question is this:
SELECT * FROM `Articulos` WHERE `borrado` != 1 AND `sexo`= 1 AND `material` = 5 AND FIND_IN_SET ('199', `empresa`) OR `Empresa` = '' ORDER BY `empresa` DESC
the condition that I understand that goes together is FIND_IN_SET ('199',
company ) OR
Company = ''
that the idea is that if there is 199 in company or company is empty, it will be executed.
Company is a field with values separated by commas.
Not having that in a parenthesis could collide with the rest of the conditions? If it is necessary to put the parentheses, what would be the syntax?
Depending on the description you give of what you want your query to do, then yes, you need to add parentheses to it. Note that operators
AND
have higher precedence than operatorsOR
, so without additional parentheses, your query is equivalent to the following:To avoid this, you must add parentheses around the last 2 conditions joined by the
OR
: