ANY answer.
Re: Insert or update a record if it already exists?
[sql]
INSERT INTO users (username)
SELECT 'Jo'
WHERE 'Jo'
NOT IN (SELECT username FROM users)
UPDATE users
SET email = 'jo@email.com'
WHERE username = 'Jo'
[/sql]
I use this method a lot. Obviously, 'Jo' would usually either be a variable or a field selected from another table.
|