Grokking SQL for Tech Interviews
Ask Author
Back to course home

0% completed

Read data from table
Table of Contents

SELECT Statement

Syntax

Example

SELECT Statement

In SQL, 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:

Image

Selecting All Columns

The simplest way to retrieve all records from a table is to use the SELECT * statement.

SELECT * from Employee;
MYSQL
MYSQL

. . . .

The result of this query would be a table showing the following rows:

Image

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 first and last names of the employees.

SELECT firstName, lastName FROM Employee;
MYSQL
MYSQL

. . . .

This query will return only the firstName and lastName columns for all employees in the Employee table.

Image
Mark as Completed

Table of Contents

SELECT Statement

Syntax

Example