Exercise – Selecting unique first names
Write an SQL statement that selects all the names from the person table without duplicates. For example, assume that there are three records in the person
table that have these first names: Jim
, Jim
, and Bill
. The SQL statement you write must return Jim
and Bill
, without repeating the name Jim
twice.
Note
We did not explain how to do it; you have to read the SQL documentation to find out how to select unique values.
Answer
Use the distinct
keyword. The following SQL statement returns unique first names:
select distinct first_name from person;