[英]SQL get ID of row on which update is performed on the same query
我想获取在同一SQL查询中正在执行UPDATE
函数的行的ID
。
像这样:
Select id
from relations
where (UPDATE relations set x1 ='0', y1='0' WHERE element_from='abc')
我知道这可以通过两个单独的查询来完成,但是有没有办法在单个查询中得到它?
表中的列:
id_main
id
type
x1
y1
x2
y2
element_from
element_to
d
session
name
您可以通过相关选择获得它
select id from relations WHERE element_from='abc'
您可以按以下方式尝试(想法取自如何获取MySQL中最后更新的行的ID? )
SET @update_id := 0;
UPDATE relations set x1 = '0', y1 = '0', id = (SELECT @update_id := id)
WHERE element_from = 'abc';
SELECT @update_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.