Contenido del Curso
Introduction to SQL
1. Retrieving Data
2. Sorting Retrieved Data
Introduction to SQL
Retrieving Distinct Rows
Note that the SELECT
statement returns all rows in a given column. However, what if we don't need all the values from a column, especially when they are duplicated, and we only need unique values? For such cases, it is convenient to use the keyword DISTINCT
, placed immediately before the column names. Let's take a look at an example:
Here's a short example of the country
table:
id | name | continent | region | surfacearea | capital | population |
---|---|---|---|---|---|---|
1 | Japan | Asia | Eastern Asia | 377829 | Tokyo | 126714000 |
2 | Latvia | Europe | NULL | 64589 | Riga | 2424200 |
3 | Mexico | North America | Central America | 1958201 | Mexico City | 98881000 |
4 | Netherlands | Europe | Western Europe | 41526 | Amsterdam | 15864000 |
... | ... | ... | ... | ... | ... | ... |
15 | Malta | Europe | Southern Europe | 316 | Valletta | 380200 |
Tarea
You have to retrieve distinct (unique) continent
values.
¿Todo estuvo claro?
Contenido del Curso
Introduction to SQL
1. Retrieving Data
2. Sorting Retrieved Data
Introduction to SQL
Retrieving Distinct Rows
Note that the SELECT
statement returns all rows in a given column. However, what if we don't need all the values from a column, especially when they are duplicated, and we only need unique values? For such cases, it is convenient to use the keyword DISTINCT
, placed immediately before the column names. Let's take a look at an example:
Here's a short example of the country
table:
id | name | continent | region | surfacearea | capital | population |
---|---|---|---|---|---|---|
1 | Japan | Asia | Eastern Asia | 377829 | Tokyo | 126714000 |
2 | Latvia | Europe | NULL | 64589 | Riga | 2424200 |
3 | Mexico | North America | Central America | 1958201 | Mexico City | 98881000 |
4 | Netherlands | Europe | Western Europe | 41526 | Amsterdam | 15864000 |
... | ... | ... | ... | ... | ... | ... |
15 | Malta | Europe | Southern Europe | 316 | Valletta | 380200 |
Tarea
You have to retrieve distinct (unique) continent
values.
¿Todo estuvo claro?