• Articles
  • Tutorials
  • Interview Questions

SELECT Query in SQL - Master the Basics

Tutorial Playlist

SELECT Statement in SQL

The Select statement in SQL is the most commonly query-used statement in SQL. It is used to either fetch data according to some specified rule or display an entire table in SQL. The data displayed after the query execution is stored in a result table.

Watch this Select Statement in SQL video

Video Thumbnail

In this tutorial section, we will discuss on:

A Brief on the SELECT Query in SQL

The Select query in SQL is one of the most important commands in SQL, and it is used to get data from a table.

Syntax

SELECT column1, column2, columnN
FROM tablename;

where SELECT and FROM are the keywords; column1 to columnN are a set of columns, and tablename is the name of the table followed by a semicolon.

How to Select Data from a Table?

  • Let’s display the name and age of an employee from the employee table
Select e_name From employee; (single column)
Select e_name, e_age From employee;

How to Select Data from a Table

  • After writing the query, click on the execute button to check for errors
  • Once the query is executed, the table appears

The Select option contains the table name and the From option contains the table name from where we want to fetch the data.

  • To select everything from a table, use * (asterisk operator)
Select * from employee;

How to Select Data from a Table 2

  • After writing the query, click on the execute button to check for errors
  • Once the query is executed, the table appears

Become a Database Architect

Select Distinct in SQL

A column often contains many duplicate values, and sometimes the information needed from a single column has to be distinct. Using the SELECT DISTINCT statement in SQL, we can filter out distinct values from a column.

Syntax

SELECT DISTINCT column1, column2, columnN
FROM tablename;

where SELECT DISTINCT and FROM are the keywords, column1 to columnN are a set of columns, and tablename is the name of the table, followed by a semicolon.

How to Select Distinct Data from a Table?

  • Let’s select some distinct values from our employee table. If we have a glance at the gender column, we can see that two values are being repeated, male and female.
select distinct e_gender from employee;

How to Select Distinct Data from a Table

  • After writing the query, click on the execute button to check for errors
  • Once the query is executed, the table appears

Let’s remove the distinct keyword and run the query.

select e_gender from employee;

How to Select Distinct Data from a Table 2

  • After writing the query, click on the execute button to check for errors
  • Once the query is executed, the table appears

When the distinct keyword was removed, all values got displayed., which gives us a clear picture of the Select Distinct statement; it gets only the values which are different.

This bring us to the end of this Select Query in SQL. Here, we learned to use Select Command in SQL and Select Distinct command in SQL .

Course Schedule

Name Date Details
SQL Training 14 Dec 2024(Sat-Sun) Weekend Batch View Details
21 Dec 2024(Sat-Sun) Weekend Batch
28 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Data Engineer

As a skilled Data Engineer, Sahil excels in SQL, NoSQL databases, Business Intelligence, and database management. He has contributed immensely to projects at companies like Bajaj and Tata. With a strong expertise in data engineering, he has architected numerous solutions for data pipelines, analytics, and software integration, driving insights and innovation.