为了账号安全,请及时绑定邮箱和手机立即绑定

MYSQL随笔

标签:
MySQL

1.mysql查询重复记录方法

select * from table1
where t_id in (select t_id from table1 group by t_id having count(t_id) > 1);

select * from table1
where t_id in (select t_id from table1 group by t_id having count(t_id) > 1);

2.mysql新建用户及分配数据库权限

CREATE USER admin123 IDENTIFIED BY 'pwd';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'pwd';

3.mysql将一张表部分字段数据更新到另一张关联表

UPDATE  tablename1 as  B, tablename2 as C
SET B.gender=C.gender
WHERE C.id=B.id

4.mysql删除重复数据,只保留一行

  • 用户表members member_name存在重复值, 删除重复值,只保留id最大一行
DELETE FROM members WHERE member_name IN 
	( SELECT t.member_name FROM ( SELECT member_name FROM members GROUP BY member_name HAVING count(1) > 1 ) t )
		AND member_id NOT IN (SELECT dt.mindeptno FROM ( SELECT max(member_id) AS mindeptno FROM members GROUP BY member_name HAVING count(1) > 1 ) dt)
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消