sql - return id on mysql create if not exists query -
i have table:
create table `table_listnames` ( `id` int(11) not null auto_increment, `name` varchar(255) not null, `address` varchar(255) not null, `tele` varchar(255) not null, primary key (`id`) ) engine=innodb;
and query:
insert table_listnames (name, address, tele) select * (select 'rupert', 'somewhere', '022') tmp not exists ( select name table_listnames name = 'rupert' ) limit 1;
i query print out id of record inserted or or selected. ideas? thanks!
you can last inserted autoincrement value last_inserted_id, see http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id.
it's idea check number of affected rows first. can execute query no matching row.
Comments
Post a Comment