How to Select data from Table in MySQL or MariaDB - MySQL Developer Tutorial

How to Select data from Table in MySQL or MariaDB

The data is saved in tables in Database / Schema in MySQL or other Relation Database management systems. Once the data is saved by manual process or by using the Application, we need to retrieve the data in Application or in Reporting. Select is the statement that we use to retrieve the data from tables/views in MySQL.

Select all Records from Table :

If we need to Select all the columns in table with all rows in table, we can use below syntax.

Select * from YourTableName;

The * in above query represents all columns.

Show Selected Column : 

We don't need to see the data from all the columns sometime. In those cases we can show or select the data from the columns we like. You can use below syntax to show select columns from a table or view in MySQL or MariaDB.

Select column1,Column2,Column3,.... From YourTableName;

Column Alias:

Sometime the column names in the tables are not that readable and you want to present more readable column names when you retrieve the records. You can Alias any column name by using "ColumnName as ColumnAliasName".

Select column1 As ColumnAlisaName, Column2,Column3,...From YourTableName;

Columns with Space in Column Names:

I don't really advise to have space in column name. But there are many scenarios when people have space in column names such as "Fist Name", in those cases when you have space between column name, you have to use acute ` around column names when using in Select or anywhere in queries.

Select `column name`, column2, `first name`, column 4 from YourTableName;

How to retrieve data from MySQL Table | Get data from MariaDB Database table

1 comment: