如何使用 MySQL 查询查找特定行?
mysqlmysqli database更新于 2025/12/20 22:04:17
首先我们创建一个表 −
mysql> create table DemoTable ( UserId int, UserName varchar(100) ); Query OK, 0 rows affected (0.66 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(100,'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(101,'Bob'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(102,'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(103,'Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(104,'Sam'); Query OK, 1 row affected (0.16 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+--------+----------+ | UserId | UserName | +--------+----------+ | 100 | Chris | | 101 | Bob | | 102 | David | | 103 | Mike | | 104 | Sam | +--------+----------+ 5 rows in set (0.00 sec)
以下是查找特定行并显示该行记录的查询 −
mysql> select *from DemoTable where UserId=102 and UserName='David';
这将产生以下输出 −
+--------+----------+ | UserId | UserName | +--------+----------+ | 102 | David | +--------+----------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

