在 MySQL 中获取特定列值(名称)
mysqlmysqli database更新于 2024/10/9 15:08:17
要获取特定列值,请使用 LIKE 子句。让我们首先创建一个表 −
mysql> create table DemoTable1809 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1809 values('John');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('Mike');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('Johnson');
Query OK, 1 row affected (0.00 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1809;
这将产生以下输出 −
+---------+ | Name | +---------+ | John | | David | | Mike | | Johnson | +---------+ 4 rows in set (0.00 sec)
这是获取特定值的查询
mysql> select * from DemoTable1809 where Name LIKE 'Johnson%';
这将产生以下输出 −
+---------+ | Name | +---------+ | Johnson | +---------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

