从Firebird中的两个重复项更新一个-更多行 [英] Update one from two of duplicates in Firebird – more rows
问题描述
如何从两个或多个重复的行中更新一个?我想保留一个并用新值更新其他.
简单的示例表:
来自
one|two|three
----------
1|milk|water
1|milk|water
到
one|two|three
----------
1|milk|water
1|milk|sugar
http://www.ibexpert.net/ibe/index.php?n=Doc.TheMysteryOfRDBDBKEY
Select *, RDB$DB_KEY from MyExampleTable;
然后
Update MyExampleTable
Set Column=Value
Where RDB$DB_KEY=xxxxx;
另一种方法是使用存储过程(或执行块)并使用SQL Cursor变量.但这需要仔细的循环管理,因此您将跳过一行并更改第二,第三等.
另请参见UPDATE ... WHERE CURRENT OF ...
的示例,网址为
https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-zh-CN/html/fblangref25-dml-update.html#fblangref25-dml-tbl-update
但是最合适的方法可能是在该表中添加唯一的主键列,然后使用该唯一的数字ID
How do I update one from two or more duplicate rows? I want to keep one and update the others with a new value.
Simple example tables:
from
one|two|three
----------
1|milk|water
1|milk|water
to
one|two|three
----------
1|milk|water
1|milk|sugar
http://www.ibexpert.net/ibe/index.php?n=Doc.TheMysteryOfRDBDBKEY
Select *, RDB$DB_KEY from MyExampleTable;
then
Update MyExampleTable
Set Column=Value
Where RDB$DB_KEY=xxxxx;
Another approach would be using Stored Procedure (or Execute Block) and use SQL Cursor variables. But that would require careful loop management, so you would skip one row and change 2nd, third and so on.
Also see examples for UPDATE ... WHERE CURRENT OF ...
at
https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-dml-update.html#fblangref25-dml-tbl-update
But probably most proper way would be to add unique Primary Key column to that table and then use that unique numeric ID
这篇关于从Firebird中的两个重复项更新一个-更多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!