在 MySQL 中獲取特定的列值(名稱)


要獲取特定的列值,請使用 LIKE 子句。我們先建立一個表 -

mysql> create table DemoTable1809
     (
     Name varchar(20)
     );
Query OK, 0 rows affected (0.00 sec)

使用插入命令在表中插入一些記錄 -

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)

更新於: 2019-12-24

760 次瀏覽

開啟你的 職業生涯

完成課程獲取認證

開始
廣告
© . All rights reserved.