MySQL SELECT

MySQL SELECT statement facilitates the retrieval of information from Tables.

MySQL SELECT Statement Syntax

Below is the Basic Syntax of MySQL SELECT Statement

MySQL SELECT Statement Examples

Examples of MySQL SELECT Statement with Constant Expression in the SELECT

Example 1: MySQL SELECT Statement with a Constant expression

In the below example, the SELECT statement has a String Constant

RESULT:
mysql-select-example1

Example 2: MySQL SELECT Statement With multiple constant expressions

In the below example the SELECT statement has one String constant and another an integer number

RESULT:
mysql-select-example2

Example 3: MySQL SELECT Statement with Alias name

In MySQL by default if we don’t specify the column Alias then for constant expression, the constant expression itself is used as Column name as seen in the above two examples. Here in the below script for the string constant column Name is the alias column name and for the number column Age is the alias column name.

RESULT:
mysql-select-example3

Examples of MySQL SELECT Statement to retrieve data from a Table

To demonstrate the retrieval of the Data from the Tables using MySQL SELECT statement, let us create a Player table with sample records as depicted in the below image by executing the following script:

player-demo-table

Example 1: Retrieve All the Records from the Player Table

We can write a query like below to get all the rows from the Player table

RESULT:
mysql-select-all-rows

Example 2: Retrieve only the Required Information

In most of the scenario’s we don’t need the table all columns data, so it is always best practice to include only the required columns in the SELECT statement to reduce unnecessary data transfer over the Network and IO’s. For example in the below script we are retrieving only the Name and State column values from the Player table.

RESULT:
mysql-select-get-required-info

Leave a Reply

Your email address will not be published. Required fields are marked *