The statement ‘select 1’ from any table name means that it returns only 1. For example, If any table has 4 records then it will return 1 four times.
Let us see an example. Firstly, we will create a table using the CREATE command.
mysql> create table StudentTable -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.51 sec)
Inserting records
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
To display all the records.
mysql> select *from StudentTable;
Here is the output.
+------+-------+ | id | name | +------+-------+ | 1 | John | | 2 | Carol | | 3 | Smith | | 4 | Bob | +------+-------+ 4 rows in set (0.00 sec)
The following is the query to implement "select 1".
mysql> select 1 from StudentTable;
Here is the output.
+---+ | 1 | +---+ | 1 | | 1 | | 1 | | 1 | +---+ 4 rows in set (0.00 sec)
The above returns 1 four times for 4 records, and if we had 5 records then the above query would have returned 1 five times.
Note: It returns 1 N times, if the table has N records.