SQL两个表数据对比

SQL两个表数据对比,第1张

select a.*,'相同数据' as note from 表A a left join 表B b

on a.name=b.name

where a.age=b.age

union all

select *,'不相同数据' as note from 表A c where c.name not in

(

select a.name from 表A a left join 表B b

on a.name=b.name

where a.age=b.age

) or c.age not in

(

select a.age from 表A a left join 表B b

on a.name=b.name

where a.age=b.age

)

union all

select *,'不相同数据' as note from 表B c where c.name not in

(

select a.name from 表A a left join 表B b

on a.name=b.name

where a.age=b.age

) or c.age not in

(

select a.age from 表A a left join 表B b

on a.name=b.name

where a.age=b.age

)

insert

into

tablea

select

*

from

tablea

where

not

exists

(selelct

'1'

from

tableb

where

tablea.serverid

=

serverid

and

tablea.driverid

=

driverid

and

tablea.driversize

=

driversize)

update

tablea

set

tablea.driversize

=

tablea.driversize

from

tablea

,tableb

where

tablea.serverid

=

serverid

and

tablea.driverid

=

driverid

如果你以tableb为准的话,你最好在tableb上加个触发器


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9424663.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存