Junior — Middle
How can you obtain a list of unique elements in the resulting dataset when executing an SQL query?
sobes.tech AI
Answer from AI
To obtain a list of unique elements in the result of an SQL query, the DISTINCT keyword is used.
Example:
SELECT DISTINCT column_name FROM table_name;
This will return all unique values from the column_name column without repetitions.
If you need to get unique combinations of multiple columns:
SELECT DISTINCT column1, column2 FROM table_name;
DISTINCT filters out duplicate rows in the result set.