Skip to content

Instantly share code, notes, and snippets.

@mfr
Created October 12, 2011 12:25
Show Gist options
  • Select an option

  • Save mfr/1281094 to your computer and use it in GitHub Desktop.

Select an option

Save mfr/1281094 to your computer and use it in GitHub Desktop.
unique value
CREATE TABLE `some_table` (
 `id` int(4) unsigned NOT NULL AUTO_INCREMENT,
 `value` varchar(255) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`),
 UNIQUE KEY `value` (`value`)
);
INSERT INTO some_table (value) VALUES ('test') ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id);
select last_insert_id();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment