让我们首先创建一个表-
mysql> create table DemoTable1528 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentSubject varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Chris','MongoDB'); mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Bob','MySQL'); mysql> insert into DemoTable1528(StudentName,StudentSubject) values('David','Java'); mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Carol','C'); mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Sam','Java'); mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Mike','Java'); mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Adam','MySQL');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1528;
这将产生以下输出-
+-----------+-------------+----------------+ | StudentId | StudentName | StudentSubject | +-----------+-------------+----------------+ | 1 | Chris | MongoDB | | 2 | Bob | MySQL | | 3 | David | Java | | 4 | Carol | C | | 5 | Sam | Java | | 6 | Mike | Java | | 7 | Adam | MySQL | +-----------+-------------+----------------+ 7 rows in set (0.00 sec)
以下是根据表列之一中的特定输入获取多个MySQL行的查询。在这里,我们的具体输入是“ Java”-
mysql> select StudentId,StudentName,StudentSubject from DemoTable1528 where StudentSubject='Java';
这将产生以下输出-
+-----------+-------------+----------------+ | StudentId | StudentName | StudentSubject | +-----------+-------------+----------------+ | 3 | David | Java | | 5 | Sam | Java | | 6 | Mike | Java | +-----------+-------------+----------------+ 3 rows in set (0.00 sec)