在删除MySQL表中的重复列时需要帮助吗?
要删除重复的列,请将DELETE与INNERJOIN一起使用。以下是语法-
delete tbl1 from yourTableName anyAliasName1 inner join yourTableName anyAliasName2 where yourCondition1 and yourCondition2
让我们创建一个表-
mysql> create table demo14 −> ( −> id int not null auto_increment primary key, −> name varchar(30) −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo14(name) values('John');
mysql> insert into demo14(name) values('David');
mysql> insert into demo14(name) values('David');
mysql> insert into demo14(name) values('Bob');
mysql> insert into demo14(name) values('John');
mysql> insert into demo14(name) values('Carol');使用select语句显示表中的记录-
mysql> select *from demo14;
这将产生以下输出-
+----+-------+ | id | name | +----+-------+ | 1 | John | | 2 | David | | 3 | David | | 4 | Bob | | 5 | John | | 6 | Carol | +----+-------+ 6 rows in set (0.00 sec)
以下是从表中删除重复列的查询-
mysql> delete tbl1 from demo14 tbl1 −> inner join demo14 tbl2 −> where −> tbl1.id < tbl2.id and −> tbl1.name = tbl2.name −> ;
使用select语句显示表中的记录-
mysql> select *from demo14;
这将产生以下输出-
+----+-------+ | id | name | +----+-------+ | 3 | David | | 4 | Bob | | 5 | John | | 6 | Carol | +----+-------+ 4 rows in set (0.00 sec)
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿