sql另辟蹊,持续更新

本贴主要摘录一些不常见的sql语句及收藏一些好的sql写法

sql如何修改一个表的字段值等于另一个表的字段值
update confer set confer.ybp=(select ybprand.ybpid from ybprand where confer.ybp=ybprand.pid )
修改confer表中的ybp字段等于ybprand表中的ybpid (同时confer表的ybp等于ybprand表的pid)

sql删除大数量的重复数据
delete from test where name in(
select t.name from test as t
group by t.name having COUNT(t.name) > 1
)
and
id not in (
select min(b.id) from test as b
group by b.name having COUNT(b.name) > 1
) -- 除了最小的那条记录不删除,其他的都删除
 
原文地址:https://www.cnblogs.com/xlhblogs/p/2664263.html