MySQL answer.
Re: Insert or update a record if it already exists?
MySQL has a special construct for this. Assume the 'username' column below is UNIQUE:
[sql]
INSERT INTO users (username, email) values ('Jo', 'jo@email.com')
ON DUPLICATE KEY UPDATE email = 'jo@email.com'
[/sql]
The 'ON DUPLICATE KEY' statement only works on PRIMARY KEY and UNIQUE columns.
|