我有2个表"A"和"B".两者都有一个共同的列名称",并通过列"id"相互链接.表A中的名称"列为空,而表B中具有数据.我的任务是用相应的ID填充从表B到表A的该列中的所有数据.
我正在使用以下查询:
UPDATE A SET A.name = (SELECT B.name from B WHERE A.id = B.id) WHERE EXISTS (SELECT B.name from B)我在SQL Developer中运行查询后,它就冻结了,我不得不强制关闭它.谁能告诉我查询出了什么问题?
解决方案请尝试以下方法:
UPDATE A SET A.name = (SELECT B.name FROM B WHERE B.id = A.id AND B.name IS NOT NULL) WHERE a.name IS NULL;由于您使用的是Oracle,因此这里是 IS NOT NULL 的参考. /p>
这里是SQL Fiddle,因此您可以使用它: sqlfiddle/#!4/a5ad0/3
I have 2 tables 'A' and 'B'. Both have a common column 'name' and linked with each other by a column 'id'. The column 'name' in the table A is empty whereas it has data in table B. My task is to fill all the data in that column from table B to table A with corresponding ids.
I'm using the following query:
UPDATE A SET A.name = (SELECT B.name from B WHERE A.id = B.id) WHERE EXISTS (SELECT B.name from B)As soon as I run the query in SQL developer, it just freezes and i have to force close it. Can anyone tell me what's wrong with the query?
解决方案Try this one instead:
UPDATE A SET A.name = (SELECT B.name FROM B WHERE B.id = A.id AND B.name IS NOT NULL) WHERE a.name IS NULL;Since you're using Oracle, here's the reference for IS NOT NULL.
Here's the SQL Fiddle so that you can play with it: sqlfiddle/#!4/a5ad0/3
更多推荐
通过另一个表中的列更新一个表中的列
发布评论