skip to Main Content

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


  1. Yes it is flipping the sign of users.registration_status before comparing it to 14 in your query

    Login or Signup to reply.
  2. 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!)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search