How to retrieve unique record from table? #sqlinterview #distinct #unique # #freshers

preview_player
Показать описание
In SQL, the `DISTINCT` keyword is used in a `SELECT` statement to retrieve unique values from a specific column or a combination of columns in a table. It ensures that the result set contains only distinct or unique rows, eliminating any duplicate entries.

The basic syntax for using `DISTINCT` is as follows:
```
SELECT DISTINCT column1, column2, ...
FROM table_name;
```

This query will return the unique combinations of values found in the specified columns, removing any duplicates from the result set.

For example, if you have a table named "employees" and you want to retrieve the unique values from the "department" column, you can use the following SQL query:
```
SELECT DISTINCT department
FROM employees;
```

This will give you a list of all unique departments present in the "employees" table, without any duplicates.

Keep in mind that using `DISTINCT` can affect the performance of a query
Рекомендации по теме