
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Is SELECT * faster than 40 columns listing in MySQL?
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)
- Related Articles
- MySQL alias for SELECT * columns?
- Do you think operator < is faster than
- Select distinct values from two columns in MySQL?
- Select distinct combinations from two columns in MySQL?
- MYSQL select DISTINCT values from two columns?
- MySQL Select Statement DISTINCT for Multiple Columns?
- How can I enhance my select query to make it faster in MySQL?
- Select aggregate function and all other columns in MySQL
- SELECT not null column from two columns in MySQL?
- Select maximum of sum of two columns in MySQL
- Why does light travel faster than sound like we see lightning faster than thunder?
- In MongoDB, is using $in search faster than multiple single searches?
- Select multiple columns and display in a single column in MySQL?
- When Java runs faster than C++?
- MySQL Select where value exists more than once

Advertisements