对于选择性的多个记录,请使用MySQL IN()
。要删除它们,请使用MySQL DELETE。让我们首先创建一个表-
mysql> create table DemoTable ( ClientId varchar(40), ClientName varchar(50) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('CLI-101','Chris'); mysql> insert into DemoTable values('CLI-110','Adam'); mysql> insert into DemoTable values('CLI-220','Mike'); mysql> insert into DemoTable values('CLI-120','Bob'); mysql> insert into DemoTable values('CLI-240','Sam');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+------------+ | ClientId | ClientName | +----------+------------+ | CLI-101 | Chris | | CLI-110 | Adam | | CLI-220 | Mike | | CLI-120 | Bob | | CLI-240 | Sam | +----------+------------+ 5 rows in set (0.00 sec)
这是删除选择性多个记录的查询-
mysql> delete from DemoTable where ClientId IN('CLI-101','CLI-220','CLI-240');
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+------------+ | ClientId | ClientName | +----------+------------+ | CLI-110 | Adam | | CLI-120 | Bob | +----------+------------+ 2 rows in set (0.00 sec)