扫码关注官方订阅号
我的sql语句如图,如何在insert的时候更新其中的project_id字段呢?
直接给你个例子,相信你能看懂,insert into users (id,username,password) select null,username,'3333' from users where id=1
insert into users (id,username,password) select null,username,'3333' from users where id=1
ON DUPLICATE KEY UPDATE 语法,这个要配合唯一索引使用
先插入insert 如果成功则 返回自增ID,再执行update 这样可以啊,执行2条SQL就行
这是要写触发器么。。。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
直接给你个例子,相信你能看懂,
insert into users (id,username,password) select null,username,'3333' from users where id=1ON DUPLICATE KEY UPDATE 语法,这个要配合唯一索引使用
先插入insert 如果成功则 返回自增ID,再执行update 这样可以啊,执行2条SQL就行
这是要写触发器么。。。