在 MySQL 中顯示除某一以外的所有記錄
您可以使用 IN() 在 MySQL 中顯示除某一以外的所有記錄。我們首先建立一個表 −
mysql> create table DemoTable ( Id int, FirstName varchar(20) ); Query OK, 0 rows affected (0.57 sec)
使用 insert 命令在表中插入一些記錄 −
mysql> insert into DemoTable values(100,'Larry'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values(10,'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(110,'Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(90,'David'); Query OK, 1 row affected (0.20 sec)
以下是使用 select 語句從表中顯示所有記錄的查詢 −
mysql> select *from DemoTable;
這將生成以下輸出 −
+------+-----------+ | Id | FirstName | +------+-----------+ | 100 | Larry | | 10 | Chris | | 110 | Robert | | 90 | David | +------+-----------+ 4 rows in set (0.00 sec)
以下是顯示 MySQL 中除某一以外的所有記錄的查詢 −
mysql> select *from DemoTable where Id IN(110,90,100);
這將生成以下輸出 −
+------+-----------+ | Id | FirstName | +------+-----------+ | 100 | Larry | | 110 | Robert | | 90 | David | +------+-----------+ 3 rows in set (0.00 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP