如何在 MySQL 中从条件为 id 和 name 的表中进行选择?
我们先创建一个表 -
mysql> create table DemoTable819( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) ); Query OK, 0 rows affected (0.88 sec)
使用 Insert 命令在表中插入一些记录 -
mysql> insert into DemoTable819(StudentName) values('Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable819(StudentName) values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable819(StudentName) values('Adam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable819(StudentName) values('Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable819(StudentName) values('Sam'); Query OK, 1 row affected (0.16 sec)
使用 Select 语句显示表中的所有记录 -
mysql> select *from DemoTable819;
这将产生以下输出 -
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Robert | | 3 | Adam | | 4 | Mike | | 5 | Sam | +-----------+-------------+ 5 rows in set (0.00 sec)
以下是查询,用于从条件为 name 和 id 的表中进行选择 -
mysql> select *from DemoTable819 where StudentName='Robert' and StudentId > 1;
这将产生以下输出 -
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 2 | Robert | +-----------+-------------+ 1 row in set (0.00 sec)
广告