[Solved] Explain SQL Query execution in this case

EverSQL Database Performance Knowledge Base

Explain SQL Query execution in this case

I am using a sql query i.e.


In this Table_Name table has 10 rows and 5 columns. When I run this above query it runs fine and return 10 rows and 5 columns.

Now I am running a new query i.e.


Now it will return only a single column but 10 rows and this single column has same values i.e. 8 in each row.

I want to know that why it return me 10 rows and a column which has only 8 value and when i am using * instead of 8 in that case it will return 10 rows and 5 columns.

What exactly the difference between both queries and its execution process?

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Avoid Selecting Unnecessary Columns (query line: 2): Avoid selecting all columns with the '*' wildcard, unless you intend to use them all. Selecting redundant columns may result in unnecessary performance degradation.
The optimized query:

Related Articles

* original question posted on StackOverflow here.