• 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


In this tutorial section, we will discuss on:

Wish to get certified in SQL! Learn SQL from top SQL experts and excel in your career with intellipaat’s SQL certification.

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

Become a SQL professional with this complete SQL Training Course!

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.

Get familiar with the top SQL Interview Questions to get a head start in your career!

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.

If you have any doubts or queries related to SQL, get them clarified from the SQL experts on our SQL Community!

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 27 Apr 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 04 May 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 11 May 2024(Sat-Sun) Weekend Batch
View Details

Database-ad.jpg