Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Retrieving Distinct Rows | Retrieving Data
Introduction to SQL

Retrieving Distinct RowsRetrieving 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

Task

You have to retrieve distinct (unique) continent values.

Everything was clear?

Section 1. Chapter 4
toggle bottom row
course content

Course Content

Introduction to SQL

Retrieving Distinct RowsRetrieving 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

Task

You have to retrieve distinct (unique) continent values.

Everything was clear?

Section 1. Chapter 4
toggle bottom row
some-alt