Contenido del Curso
SQL Basics
SQL Basics
Unique values from multiple columns
But what if we want to know, for example, unique pairs 'country-city' of our site visitors? Surely, we can extract unique countries (like in the previous chapter) and unique cities. But then we have to connect each city to the country manually.
This task can be solved by the same DISTINCT
, but this time with two columns. For example,
SELECT DISTINCT(country), city FROM visitors
The
DISTINCT
statement will return all the unique combinations of columns you chose. Using parentheses is not mandatory, i.e. you for the example above you can writeDISTINCT country, city
. But placing multiple columns withinDISTINCT
parentheses will return only one column of all unique combinations in(country, city)
format.
Tarea
Extract all unique combinations of model
and transmission
¡Gracias por tus comentarios!
Unique values from multiple columns
But what if we want to know, for example, unique pairs 'country-city' of our site visitors? Surely, we can extract unique countries (like in the previous chapter) and unique cities. But then we have to connect each city to the country manually.
This task can be solved by the same DISTINCT
, but this time with two columns. For example,
SELECT DISTINCT(country), city FROM visitors
The
DISTINCT
statement will return all the unique combinations of columns you chose. Using parentheses is not mandatory, i.e. you for the example above you can writeDISTINCT country, city
. But placing multiple columns withinDISTINCT
parentheses will return only one column of all unique combinations in(country, city)
format.
Tarea
Extract all unique combinations of model
and transmission
¡Gracias por tus comentarios!
Unique values from multiple columns
But what if we want to know, for example, unique pairs 'country-city' of our site visitors? Surely, we can extract unique countries (like in the previous chapter) and unique cities. But then we have to connect each city to the country manually.
This task can be solved by the same DISTINCT
, but this time with two columns. For example,
SELECT DISTINCT(country), city FROM visitors
The
DISTINCT
statement will return all the unique combinations of columns you chose. Using parentheses is not mandatory, i.e. you for the example above you can writeDISTINCT country, city
. But placing multiple columns withinDISTINCT
parentheses will return only one column of all unique combinations in(country, city)
format.
Tarea
Extract all unique combinations of model
and transmission
¡Gracias por tus comentarios!
But what if we want to know, for example, unique pairs 'country-city' of our site visitors? Surely, we can extract unique countries (like in the previous chapter) and unique cities. But then we have to connect each city to the country manually.
This task can be solved by the same DISTINCT
, but this time with two columns. For example,
SELECT DISTINCT(country), city FROM visitors
The
DISTINCT
statement will return all the unique combinations of columns you chose. Using parentheses is not mandatory, i.e. you for the example above you can writeDISTINCT country, city
. But placing multiple columns withinDISTINCT
parentheses will return only one column of all unique combinations in(country, city)
format.
Tarea
Extract all unique combinations of model
and transmission