The SELECT * is slower than 40 columns listing. It’s a better choice to list the column names while using the SELECT query. Let us see a simple example and create a table −
mysql> create table DemoTable( Id int, Name varchar(20), Age int, ZipCode varchar(20), CountryName varchar(20) ); Query OK, 0 rows affected (0.82 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(101,'Chris',23,'0909332','US'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable values(102,'Bob',24,'8747443','AUS'); Query OK, 1 row affected (0.50 sec) mysql> insert into DemoTable values(103,'Adam',21,'9988833','UK'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+-------+------+---------+-------------+ | Id | Name | Age | ZipCode | CountryName | +------+-------+------+---------+-------------+ | 101 | Chris | 23 | 0909332 | US | | 102 | Bob | 24 | 8747443 | AUS | | 103 | Adam | 21 | 9988833 | UK | +------+-------+------+---------+-------------+ 3 rows in set (0.00 sec)
Now, we will list every column name while using MySQL SELECT since it is considered a faster approach −
mysql> select Id,Name,Age,ZipCode,CountryName from DemoTable;
This will produce the following output −
+------+-------+------+---------+-------------+ | Id | Name | Age | ZipCode | CountryName | +------+-------+------+---------+-------------+ | 101 | Chris | 23 | 0909332 | US | | 102 | Bob | 24 | 8747443 | AUS | | 103 | Adam | 21 | 9988833 | UK | +------+-------+------+---------+-------------+ 3 rows in set (0.00 sec)