简体   繁体   中英

How to write SQL Query for this case?

Suppose I have a tableA -

id value
1 a
2 d

tableB

idTableA someValue someOtherValue
1 de
1 xy

Now in tableB I want to insert rows where idTableA would come from tableA and custom values in somevalue and 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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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