开发者

Get specific value from table A and copy that result into Table B?

is there a way to get the result from a query and copy that result to a different table in a specic column.

here is what i have so far

//get CONTACT_ID from RETAILER_ID and create some loop that goes through all CONTACT_ID values and execute the queries below:

select CSN from CONTACTS where CONTACT_ID = '103309';

The开发者_如何转开发 above query gets the CSN value from CONTACTS table and i want to execute something below:

update RETAILER_CONTACTS set columnB = new CSN where CONTACTS_ID='103309';

I will need to do this for every single record in the RETAILER_CONTACTS hence why i need to execute the above in some loop that goes through each CONTACTS_ID i find from the below query:

Select CONTACT_ID from RETAILER_ID;

Thanks in advance


Not sure I've understood what you want to do, but most of the time, a desire to use loops in SQL is a sign of trouble. I think you can do what you want by something like:

update RETAILER_CONTACTS 
set columnB = CSN
from RETAILER_CONTACTS RC, 
     CONTACTS C, 
     RETAILERS R
where C.CONTACT_ID = '103309'
and   C.CONTACT_ID = RC.CONTACT_ID
and   C.RETAILER_ID = RC.RETAILER_ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜