Simple MySQL IF statement troubles
Posted on 2009-04-20
I'm having some trouble using an IF statement in a simple query. I've not used SQL much so i'm not really sure of the syntax!
I basically want to say IF this data does not exist in the table, then insert this other data.
I tried something like this:
SET @existCount=0; SELECT @existCount := COUNT(*) FROM user_data WHERE username = 'Lexx87'; IF @existCount = 0 THEN INSERT into user_data values ('Lexx87', '1000Hz', 10)
Meaning if the count is at 0 (No username Lexx87 exists) then insert those values, but it doesn't seem happy with that!
I've taken some of that syntax from a different thread, so it may be out of date but I don't know!
Any help will be appreciated.