I am encountering a rather peculiar syntax in MySQL, specifically the presence of a ‘-‘ symbol within the WHERE condition in the following query.
SELECT
users.id
FROM
users
WHERE
users.account_status >= 3
AND users.account_status NOT IN (8 , 9)
AND - users.registration_status = 14
AND users.id IN (229);
I’ve researched this syntax in here?
Could it possibly indicate a transformation of the value of the ‘registration_status’ column into a negative number?
2
Answers
Yes it is flipping the sign of users.registration_status before comparing it to 14 in your query
It’s the unary minus operator. The following expressions are all equivalent:
- users.registration_status = 14
0 - users.registration_status = 14
users.registration_status = -14
with the latter probably being the most obvious (code clarity is important!)