如何在MySQL中处理多个AND条件?
要在MySQL中使用多个AND条件,以下是语法-
select *from yourTableName where yourColumnName1=yourValue1 and yourColumnName2=yourValue2 and yourColumnName3=yourValue3;
让我们首先创建一个表-
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAge int, StudentCountryName varchar(40) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('John',23,'US');
mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('Carol',21,'UK');
mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('John',21,'US');
mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('John',21,'AUS');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-----------+-------------+------------+--------------------+ | StudentId | StudentName | StudentAge | StudentCountryName | +-----------+-------------+------------+--------------------+ | 1 | John | 23 | US | | 2 | Carol | 21 | UK | | 3 | John | 21 | US | | 4 | John | 21 | AUS | +-----------+-------------+------------+--------------------+ 4 rows in set (0.00 sec)
以下是MySQL中多个AND条件的查询-
mysql> select *from DemoTable where StudentName="John" and StudentAge=21 and StudentCountryName="AUS";
输出结果
+-----------+-------------+------------+--------------------+ | StudentId | StudentName | StudentAge | StudentCountryName | +-----------+-------------+------------+--------------------+ | 4 | John | 21 | AUS | +-----------+-------------+------------+--------------------+ 1 row in set (0.00 sec)
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短