Understanding the Use of the DISTINCT Keyword in SQL for Retrieving Unique Values, Assignments of Database Programming

The distinct keyword is a crucial component of sql (structured query language) used in database management systems to retrieve unique values from a table. The syntax and usage of the distinct keyword with examples, demonstrating how it removes duplicate records while retrieving records from a table. This knowledge is essential for database administrators, data analysts, and developers.

Typology: Assignments

2021/2022

Uploaded on 03/25/2022

asimahsan45
asimahsan45 🇵🇰

5

(1)

40 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DISTINCTkeyword
Thedistinctkeyword is used withSELECTstatement to retrieve
unique values from the table.Distinctremoves all the
duplicate records while retrieving records from any table in
the database.
Syntax forDISTINCTKeyword
SELECT DISTINCT column-name FROM table-name;
Example usingDISTINCTKeyword
Consider the followingEmptable. As you can see in the table
below, there is employeename, along with
employeesalaryandage.
In the table below, multiple employees have the same salary,
so we will be usingDISTINCTkeyword to list down distinct
salary amount, that is currently being paid to the employees.
eid name age salary
pf3

Partial preview of the text

Download Understanding the Use of the DISTINCT Keyword in SQL for Retrieving Unique Values and more Assignments Database Programming in PDF only on Docsity!

DISTINCT keyword

The distinct keyword is used with SELECT statement to retrieve unique values from the table. Distinct removes all the duplicate records while retrieving records from any table in the database. Syntax for DISTINCT Keyword SELECT DISTINCT column-name FROM table-name; Example using DISTINCT Keyword Consider the following Emp table. As you can see in the table below, there is employee name , along with employee salary and age. In the table below, multiple employees have the same salary, so we will be using DISTINCT keyword to list down distinct salary amount, that is currently being paid to the employees. eid name age salary

401 Anu 22 5000 402 Shane 29 8000 403 Rohan 34 10000 404 Scott 44 10000 405 Tiger 35 8000 SELECT DISTINCT salary FROM Emp; The above query will return only the unique salary from Emp table. sala ry 5000 8000 1000