SQL记录
删除重复数据:
id 为主键 name 为有重复的字段
DELETE FROM table1 WHERE id NOT IN (SELECT MIN(id) FROM table1 GROUP BY name)
用其他表中的值更新表:
table1为要更新的表,id为主键,score为要被更新的字段
table1和table2的结构都为
id score
以table2中对应id的score来更新table1中对应id的score。
MySQL:
UPDATE table1 t1 SET t1.score = (SELECT t2.score FROM table2 t2 WHERE t2.id=t1.id) WHERE EXISTS (SELECT NULL FROM table2 t2 WHERE t2.id=t1.id)
SQL Server:
UPDATE t1 SET t1.score = t2.score FROM table1 t1,table2 t2 WHERE t2.id=t1.id
貌似MSSQL的要比MySQL的简单一些……

最近评论