How do I write a MySQL query to check for a record in the table, if yes the record exists, then update the data in the table, and if not, then insert new data into the table. I have tried the below code but the documentation suggests the syntax works only for functions and procedures. I am looking for a query that can be executed directly.
IF EXISTS (SELECT * FROM order WHERE username=:username)
UPDATE order SET orders=1 WHERE username=:username
ELSE
INSERT INTO order (username, orders) VALUES (:username, 1)