问题描述
我有一个表行(ID,LineNo,LineName),其值为:
I have a table line (ID, LineNo, LineName) having values as :
1, 1, <blank>
2, 2, <blank>
3, 3, <blank>
现在,我必须编写一个查询,以使其更新来自空白表(如上显示为< blank>)的行表中的LineName列,其值来自表linet(linenamet)的值为:
Now i have to write a query such that it updates LineName column from line table which is blank(as shown above with <blank>) with values from table linet(linenamet) having values as :
a
b
c
我的试用查询是:
更新行集LineName =(从linet中选择linenamet);
它给出错误为:子查询返回多于1行"
预期结果:
更新后,它应将行表显示为:
My trial query is :
update line set LineName = (select linenamet from linet);
It gives error as : "Subquery returns more than 1 row"
Expected Result:
After Updation it should show line table as:
1, 1, a
2, 2, b
3, 3, c
请让我知道相同的更新SQL查询.
感谢和问候,
Kindly let me know the update SQL query for the same.
Thanks and Regards,
推荐答案
update line set LineName = (select linenamet from linet --include some condition which gives you exact single result from corrosponding table)
如果linenamet
表中只有一列,那么我认为是无法获取的.
If there''s a single column in linenamet
table then I think it is not possible to fetch.
UPDATE line SET LineName = (SELECT linenamet FROM linet ln WHERE ln.ID = line.ID)
linet中名为ID的列是引用表行列LineNo的外键:
Column named ID in linet is foreign key referencing table line column LineNo:
UPDATE line SET LineName = (SELECT linenamet FROM linet ln WHERE ln.LineNo = line.ID)
由于我们不知道表linet是否具有任何外键或您根本不需要告诉我们的任何键.也许有第三个表使表之间的关系为线和线.
最好的问候,
曼弗雷德(Manfred)
Since we don''t know if table linet has any foreign key or any key at all you need to tell us. Maybe there is a third table that makes the relation between the tables linet and line.
Best Regards,
Manfred
这篇关于更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!