什么意思是在MySQL表中选择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 教程
插入记录
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条记录,则返回4次1,如果有5条记录,则上面的查询将返回5次1。
注:如果表中有N条记录,则返回1 N次。