记录两条SQL语句,免得忘了
第一条:查找单表重复记录
SELECT * FROM table_name WHERE column IN (SELECT column FROM table_name GROUP BY column HAVING COUNT(column)>1)实例:
SELECT * FROM `stu_info` WHERE telenum IN (SELECT telenum FROM stu_info GROUP BY telenum HAVING COUNT(telenum)>1)
第二条:根据一个表的某个字段更新另一个表的某个字段
UPDATE table1 SET column = (SELECT table2.date FROM table2 WHERE table1.column = table2.column)实例:
UPDATE `stu_info` SET date = (SELECT all_info.date FROM all_info WHERE stu_info.telenum = all_info.telenum)
以上语句很简单,均为语句嵌套,可以自行理解
发表评论