在表列之一中获取基于具体输入的多行 MySQL 吗?
让我们首先创建一个表 −
mysql> create table DemoTable1528 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentSubject varchar(20) -> ); Query OK, 0 rows affected (0.53 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Chris','MongoDB'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Bob','MySQL'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1528(StudentName,StudentSubject) values('David','Java'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Carol','C'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Sam','Java'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Mike','Java'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1528(StudentName,StudentSubject) values('Adam','MySQL'); Query OK, 1 row affected (0.13 sec)
使用 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)
广告