让我们首先创建一个表-
mysql> create table DemoTable819( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable819(StudentName) values('Chris'); mysql> insert into DemoTable819(StudentName) values('Robert'); mysql> insert into DemoTable819(StudentName) values('Adam'); mysql> insert into DemoTable819(StudentName) values('Mike'); mysql> insert into DemoTable819(StudentName) values('Sam');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable819;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Robert | | 3 | Adam | | 4 | Mike | | 5 | Sam | +-----------+-------------+ 5 rows in set (0.00 sec)
以下是从表中选择的查询,其中为名称和ID设置了条件-
mysql> select *from DemoTable819 where StudentName='Robert' and StudentId > 1;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 2 | Robert | +-----------+-------------+ 1 row in set (0.00 sec)