Select Query in SQL

The statement Select in SQL is the most commonly used statement in SQL for queries. It is either used to collect data according to a given rule, or to display a whole table. The data displayed after execution of the query is stored in a table of results.

In this tutorial section, we will discuss on:

Select Statement in SQL

Select Distinct in SQL

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;

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;

After the query is written, click the execute button to check for errors

The table will appear after the query has been executed

Select Distinct in SQL

A column sometimes includes multiple duplicate values, and often the necessary information from a single column has to be distinct. Using the statement SELECT DISTINCT we can filter out separate values from a column.

Syntax

SELECT DISTINCT column1, column2, columnN

FROM tablename;

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

How to Select Distinct Data from a Table?

Let’s select a few distinct values from our table of employees. If we take a look at the gender column we can see that two beliefs, male and female, are being replicated.

select distinct e_gender from employee;

select distinct data from table

After the query is written, click the execute button to check for errors

The table will appear after the query has been executed

Let’s remove the separate keyword and execute query.

select e_gender from employee;

After the query is written, click the execute button to check for errors

The table will appear after the query has been executed

Upon removal of the distinct keyword, all values were displayed, which gives us a clear picture of the Select Distinct statement; it only gets the different values.

That takes us to the end of this select SQL Query. Here we learned how to use SQL Select Command and SQL Select Distinct Order.

Leave a Reply