我是stackoverflow的新手。几周来我一直坚持这个问题,但我无法找到类似的例子(如果我错了,请纠正我)。我想要实现的是从另一个表更新一个表的值,但使用类似的关键字,例如。我有2张桌子
table1(id,item)值:
id | item
-------------
10 | book
20 | copy
30 | pen
table2(id,item)值:
id | item
-------------
null | the big book
null | the copy machine
null | penpal
现在我想:
Update table2 A
Set id = Select id From table1 B
Where A.item Like B.item;
我希望的结果是: -
id | item
-------------
10 | the big book
20 | the copy machine
30 | penpal
它是如何做到的?谢谢你们。
答案 0 :(得分:1)
update table2 set id =
(select min(id) from table1
where table2.item like '%' || table1.item ||'%' );
答案 1 :(得分:1)
合并:
<div class="container">
<div class="row">
<h2> Sign In </h1>
<form action="p1.php" method="POST">
<div>some validation error</div> Username: <br/>
<input type="text" name="username" /> <br/> Password:
<input type="password" name="password" /> <br/>
<input type="submit" name="submit" id="login" />
</form>
<form action="register.php" method="POST">
<input type="submit" name="register" value="Create New Account" id="signup" />
</form>
</div>
</div>
此解决方案可能更快。
答案 2 :(得分:0)
update table2 t2
set id = ( select min(id) from table1 t1 where item like '%' || t1.item || '%')
where exists ( select 1 from table1 t1 where item like '%' || t1.item || '%');