Contenido del Curso
SQL Intermedio
SQL Intermedio
Combinación de Resultados de Tablas
Swipe to show code editor
Your task will be to combine the employees
and contractors
tables using the UNION
clause.
After that, from the resulting table, you should retrieve only those IDs that are multiples of 2. Also, you need to retrieve the first_name
and last_name
columns. Use the syntax WHERE id % 2 = 0
. For this task, you need to use subqueries in the FROM
section just as shown in the example.
Note
As a result, you should have 3 columns:
id
(an alias for the ID from both tables),first_name
,last_name
.
Brief Instructions
- Retrieve the
id
,first_name
, andlast_name
columns. - In the
FROM
clause, write two inner queries joined by theUNION
clause. - In the first inner query, select
employee_id
,first_name
, andlast_name
from theemployees
table.- Assign the alias
id
toemployee_id
.
- Assign the alias
- In the second inner query, select
contractor_id
,first_name
, andlast_name
from thecontractors
table.- Assign the alias
id
tocontractor_id
.
- Assign the alias
- Assign the alias
combined
to both inner queries. - Finally, use a
WHERE
clause with the conditionid % 2 = 0
.
¡Gracias por tus comentarios!
Combinación de Resultados de Tablas
Swipe to show code editor
Your task will be to combine the employees
and contractors
tables using the UNION
clause.
After that, from the resulting table, you should retrieve only those IDs that are multiples of 2. Also, you need to retrieve the first_name
and last_name
columns. Use the syntax WHERE id % 2 = 0
. For this task, you need to use subqueries in the FROM
section just as shown in the example.
Note
As a result, you should have 3 columns:
id
(an alias for the ID from both tables),first_name
,last_name
.
Brief Instructions
- Retrieve the
id
,first_name
, andlast_name
columns. - In the
FROM
clause, write two inner queries joined by theUNION
clause. - In the first inner query, select
employee_id
,first_name
, andlast_name
from theemployees
table.- Assign the alias
id
toemployee_id
.
- Assign the alias
- In the second inner query, select
contractor_id
,first_name
, andlast_name
from thecontractors
table.- Assign the alias
id
tocontractor_id
.
- Assign the alias
- Assign the alias
combined
to both inner queries. - Finally, use a
WHERE
clause with the conditionid % 2 = 0
.
¡Gracias por tus comentarios!