Skip to Content
TheCornerLabs Docs
Grokking SQL for Tech InterviewsA Quick Review of SQLRead Data from Table

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:

1706851860642811 Image scaled to 60%

Selecting All Columns

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

SELECT * from Employee;

Database Exercise

Database Schema:

-- Database schema would be rendered here

Exercise Script:

-- Exercise script would be rendered here

Available actions: Execute

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

1706852850333054 Image scaled to 60%

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;

Database Exercise

Database Schema:

-- Database schema would be rendered here

Exercise Script:

-- Exercise script would be rendered here

Available actions: Execute

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

1706853033733025 Image scaled to 60%

Last updated on