为此,您可以使用多个OR。让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(10), LastName varchar(10), Age int, CountryName varchar(10) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(FirstName,LastName,Age,CountryName) values('John','Smith',21,'US'); mysql> insert into DemoTable(FirstName,LastName,Age,CountryName) values('Carol','Taylor',22,'AUS'); mysql> insert into DemoTable(FirstName,LastName,Age,CountryName) values('David','Miller',19,'UK');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----+-----------+----------+------+-------------+ | Id | FirstName | LastName | Age | CountryName | +----+-----------+----------+------+-------------+ | 1 | John | Smith | 21 | US | | 2 | Carol | Taylor | 22 | AUS | | 3 | David | Miller | 19 | UK | +----+-----------+----------+------+-------------+ 3 rows in set (0.00 sec)
以下是选择一行的查询,其中几列之一等于某个值-
mysql> select *from DemoTable where FirstName="Carol" OR Age=22 OR CountryName="AUS";
输出结果
+----+-----------+----------+------+-------------+ | Id | FirstName | LastName | Age | CountryName | +----+-----------+----------+------+-------------+ | 2 | Carol | Taylor | 22 | AUS | +----+-----------+----------+------+-------------+ 1 row in set (0.00 sec)