您好,我有这个查询返回存在于一个表中但不存在于另一个表中的客户列表。 对于每个返回的 customer_id,我需要在配置文件表中添加 2 行。
我将如何在 sql 中写入 2 行的插入?
select * FROM
(select *
from customer c
left outer join profile cp
on cp.customer_id=c.global_id
order by c.global_id) as A
where id is NULL;
谢谢!
最佳答案
一种选择是使用交叉连接
创建笛卡尔积
:
insert into profile (customerid ...)
select customerid ...
FROM
(select *
from customer c
left outer join profile cp
on cp.customer_id=c.global_id
) as A cross join (SELECT 1 col UNION SELECT 2) as B
where id is NULL;
关于sql - 从一个选择中插入 2 个不同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27178781/