2009-07-30 53 views
0
SELECT (b.descr || ' - ' || c.descr) description 
FROM table1 a 
    INNER JOIN table2 b ON a.account = b.account 
    INNER JOIN table3 c ON a.product = c.product 
WHERE a.descr = ' ' ; 

如何使用上述子查询更新表?其回归多行近8000行?如果您有任何解决方案,请与我分享?带有子查询的更新表返回多个行

+0

请发表创建表脚本 - 它为我们节省了所有时间。 – Liao 2009-07-30 07:52:19

+0

Prem,你似乎有*四个问题,包括这个问题,你面对的是*同样的问题*。 1)http://stackoverflow.com/questions/1199733/getting-extra-rows-after-joing-the-3-tables-using-left-join 2)http://stackoverflow.com/questions/ 1198183/update-a-table-using-the-fields-of-the-other-two-table-please-help-me-in-this 3)http://stackoverflow.com/questions/1204563/updating- row-with-subquery-returning-multiple-rows – Liao 2009-07-30 08:02:24

+0

此外,请花些时间阅读StackOverflow FAQ。 (3条评论 - 我知道 - 下次更好!) – Liao 2009-07-30 08:04:55

回答

1

我不明白你到底想要做什么,但你可以在一个子查询语句中使用子查询:

UPDATE table1 a SET a.descr = (
    SELECT MAX(b.descr || ' - ' || c.descr) 
    FROM table2 b, table3 c 
    WHERE b.account = a.account AND c.product = a.product 
) 
WHERE a.descr = ' ' 

的MAX()将只选择一个数值为您服务。如果你想自己选择它,要么进一步限制子查询

1

在两个Oracle & SQL Sever中,如果子查询返回多于1行,数据库将报告错误。在你的情况下,如果子查询结果值是相同的,只需使用MAX()或MIN()函数让DB选择一个值。

0

尝试:

UPDATE a SET descr = (b.descr || ' - ' || c.descr) 
FROM table1 a 
    INNER JOIN table2 b ON a.account = b.account 
    INNER JOIN table3 c ON a.product = c.product 
WHERE a.descr = ' ' ; 

在有多个行,表1将最终看到的最后一个。

Rob