DISTINCT Keyword
The DISTINCT keyword retrieves unique values or records from a table, eliminating duplicates. It is applied with the SELECT statement to obtain unique values of one or more columns. Consider a sales table with customer ID, name, product, and price. To find the unique products in the sales table, we can use the DISTINCT keyword.
Syntax:
SELECT DISTINCT column(s) FROM table_name
DISTINCT vs GROUP BY in SQL
SQL (Structured Query Language) is used to manage and manipulate the data in relational databases. It can be used for tasks such as database querying, data editing, database and table creation and deletion, and granting user permissions.
We can use the DISTINCT keyword and GROUP BY clause when we want to obtain the unique records of a table in SQL. Even though their purpose is the same, they are used in various ways and they also function differently.