The DISTINCT keyword is used in SQL to eliminate duplicate rows from the result of a query. It is used to return only unique values from a column or set of columns in a table. The basic syntax of using the DISTINCT keyword is as follows:
SELECT DISTINCT column1, column2, ..., column_n FROM table_name;
In this syntax,
column_n are the names of the columns you want to return unique values from.
Let’s take a look at a few examples to understand the DISTINCT keyword better:
SELECT DISTINCT city FROM customers;
In this example, the query returns a table with a list of unique cities from the
city column in the
customers table. If there are any duplicate city names, they will only appear once in the result.
SELECT DISTINCT product_name, category FROM products;
In this example, the query returns a table with a list of unique combinations of product names and categories from the
category columns in the
products table. If there are any duplicate combinations of product names and categories, they will only appear once in the result.
SELECT DISTINCT first_name, last_name FROM employees;
In this example, the query returns a table with a list of unique first and last names from the
last_name columns in the
employees table. If there are any employees with the same first and last names, they will only appear once in the result.
In conclusion, the DISTINCT keyword is a useful tool for eliminating duplicate values from the result of a query in SQL. It helps you to obtain a clean and concise representation of your data, making it easier to analyze and understand.
Also check WHAT IS GIT ? It’s Easy If You Do It Smart
You can also visite the Git website (https://git-scm.com/)