Redian新闻
>
万佛,请教一个数据库问题
avatar
万佛,请教一个数据库问题# PhotoGear - 摄影器材
s*a
1
mysql
怎样用一个表更新另一个表,如果主键存在就略过,不存在就写入?
包子
avatar
l*g
2
能不能用subquery?
t1 destination
t2 source
insert into t1
from
(
select rows on t2 but not on t1
)
avatar
s*a
3

如果两表结构并不完全相同,而是想用主键来判断呢

【在 l******g 的大作中提到】
: 能不能用subquery?
: t1 destination
: t2 source
: insert into t1
: from
: (
: select rows on t2 but not on t1
: )

avatar
l*g
4
1. 两表结构并不完全相同
well, we have to assume everything you need for insert could be found from
f2, right? otherwise, you are missing data source anyway.
if that's true, then you can get from f2 section in the subquery, right?
2. 想用主键来判断
that's what you do in the subquery? 主键is primary key(s), right?
for quick example:
insert into t1
select fields from f2 from
(
t2 outer join t1 by key
minus
t2 equal join t1 by key
)
In short, you need to think about mathematics matirx before detailed
implementation with specific database.

【在 s****a 的大作中提到】
:
: 如果两表结构并不完全相同,而是想用主键来判断呢

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。