在 MySQL 表中,select 1 意味著什麼?


語句 select 1 從任何表名中意為它只返回 1。例如,如果任何表有 4 條記錄,它將返回 1 四次。

我們來看一個例子。首先,我們將使用 CREATE 命令 建立一個表

mysql> create table StudentTable
   -> (
   -> id int,
   -> name varchar(100)
   -> );
Query OK, 0 rows affected (0.51 sec)

插入記錄

mysql> insert into StudentTable values(1,'John'),(2,'Carol'),(3,'Smith'),(4,'Bob');
Query OK, 4 rows affected (0.21 sec)
Records: 4  Duplicates: 0  Warnings: 0

顯示所有記錄

mysql> select *from StudentTable;

以下是輸出。

+------+-------+
| id   | name  |
+------+-------+
|    1 | John  |
|    2 | Carol |
|    3 | Smith |
|    4 | Bob   |
+------+-------+
4 rows in set (0.00 sec)

以下是實現“select 1”的查詢。

mysql> select 1 from StudentTable;

以下是輸出。

+---+
| 1 |
+---+
| 1 |
| 1 |
| 1 |
| 1 |
+---+
4 rows in set (0.00 sec)

對於 4 條記錄,上述返回 1 四次,如果我們有 5 條記錄,則上述查詢將返回 1 五次。

Note: It returns 1 N times, if the table has N records.

更新於: 22-10-2023

超過 2.8 萬次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始
廣告