Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Combining Table Results | Nested Subqueries
Intermediate SQL
course content

Kurssisisältö

Intermediate SQL

Intermediate SQL

1. Grouping
2. Nested Subqueries
3. Joining Tables
4. DDL and DML in SQL

book
Challenge: Combining Table Results

Tehtävä

Swipe to start coding

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, and last_name columns.
  • In the FROM clause, write two inner queries joined by the UNION clause.
  • In the first inner query, select employee_id, first_name, and last_name from the employees table.
    • Assign the alias id to employee_id.
  • In the second inner query, select contractor_id, first_name, and last_name from the contractors table.
    • Assign the alias id to contractor_id.
  • Assign the alias combined to both inner queries.
  • Finally, use a WHERE clause with the condition id % 2 = 0.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 6
toggle bottom row

book
Challenge: Combining Table Results

Tehtävä

Swipe to start coding

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, and last_name columns.
  • In the FROM clause, write two inner queries joined by the UNION clause.
  • In the first inner query, select employee_id, first_name, and last_name from the employees table.
    • Assign the alias id to employee_id.
  • In the second inner query, select contractor_id, first_name, and last_name from the contractors table.
    • Assign the alias id to contractor_id.
  • Assign the alias combined to both inner queries.
  • Finally, use a WHERE clause with the condition id % 2 = 0.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 6
Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt