简体   繁体   English

在这种情况下,如何编写SQL查询?

[英]How to write SQL Query for this case?

Suppose I have a tableA - 假设我有一张桌子A-

id value id值
1 a 1个
2 d 2天

tableB 表B

idTableA someValue someOtherValue idTableA someValue someOtherValue
1 de 1天
1 xy 1 xy

Now in tableB I want to insert rows where idTableA would come from tableA and custom values in somevalue and someOtherValue. 现在在tableB中,我想插入idTableA来自tableA的行,并在somevalue和someOtherValue中添加自定义值。

I want to write a query like this: 我想写这样的查询:

insert into B (idTableA,someValue,someOtherValue)
values(idTableAValue, 'value1', 'value2') 
(select idTableA from TableA )    

What is the best way to do this? 做这个的最好方式是什么?

Try this: 尝试这个:

insert into B (idTableA, someValue, someOtherValue)
select idTableA, 'value1', 'value2' 
from TableA 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM