Read data from table
In this tutorial, we are going to discuss about how to read data from table. Reading data from a table in SQL is done using the SELECT
statement. This statement is part of the Data Query Language (DQL) and allows you to retrieve data from one or more tables in a relational database.
![Read data from table](https://waytoeasylearn.com/storage/2024/07/DQL.jpg)
Here’s a detailed guide on how to read data from a table using the SELECT
statement, including various options and techniques to filter, sort, and aggregate data.
SELECT
In MySQL, to read data from a table, you need to use the SELECT statement in your queries. The SELECT statement allows you to fetch data from one or more columns of a table, making it an essential tool for data retrieval.
Syntax
SELECT * FROM table_name;
The * symbol is a wildcard representing all columns in the specified table.
Example
Let’s see some examples of retrieving all or specific data from the database table.
Suppose we have a table named employee
with the following data:
id | emp_name | age | city | salary |
1 | Ashok Kumar | 32 | Hyderabad | 45000 |
2 | Dillesh | 34 | Hyderabad | 49000 |
Selecting All Columns
The simplest way to retrieve all records from a table is to use the SELECT * statement.
SELECT * from employee;
The result of this query would be a table showing the following rows:
id | emp_name | age | place | salary |
1 | Ashok Kumar | 32 | Hyderabad | 45000 |
2 | Dillesh | 34 | Hyderabad | 49000 |
Selecting Specific Columns
While retrieving all columns can be useful, there are situations where we may only need specific columns from a table. To do this, we can list the column names we want to retrieve after the SELECT keyword.
Suppose we want to retrieve the employee name and age of the employees.
SELECT emp_name, age FROM Employee;
This query will return only the emp_name and age columns for all employees in the employee
table.
emp_name | age |
Ashok Kumar | 32 |
Dillesh | 34 |
That’s all about Read data from table in SQL. If you have any queries or feedback, please write us at contact@waytoeasylearn.com. Enjoy learning, Enjoy SQL..!!