gmaxia |
| 2006-12-24 10:33 (UTC) |
| first it comes to mind |
Given this table, with the following contents
create table t1 (col1 int not null auto_increment primary key, col2 char(10));
INSERT INTO t1 values (1,'abc'), (2, 'def'), (3, 'ghi');
select * from t1;
+------+------+
| col1 | col2 |
+------+------+
| 1 | abc |
| 2 | def |
| 3 | ghi |
+------+------+
Here is an INSERT statement that will also record what it is inserted:
insert into t1
col2= @var2 := coalesce(col2,'xxx')
on duplicate key update col2 = @var2;
select @var1 := last_insert_id()as last_id , @var2;
+---------+-------+
| last_id | @var2 |
+---------+-------+
| 4 | xxx |
+---------+-------+
insert into t1
set col1= @var1,
col2= @var2 := coalesce(col2,'yyy')
on duplicate key update col2 = @var2;
select @var1, @var2;
+-------+-------+
| @var1 | @var2 |
+-------+-------+
| 4 | zzz |
+-------+-------+
Merry Christmas!
Reply | Thread | Link