Aan de slagGa gratis aan de slag

Migrate data with INSERT INTO SELECT DISTINCT

Now it's finally time to migrate the data into the new tables. You'll use the following pattern:

INSERT INTO ... 
SELECT DISTINCT ... 
FROM ...;

It can be broken up into two parts:

First part:

SELECT DISTINCT column_name1, column_name2, ... 
FROM table_a;

This selects all distinct values in table table_a – nothing new for you.

Second part:

INSERT INTO table_b ...;

Take this part and append it to the first, so it inserts all distinct rows from table_a into table_b.

One last thing: It is important that you run all of the code at the same time once you have filled out the blanks.

Deze oefening maakt deel uit van de cursus

Introduction to Relational Databases in SQL

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- Insert unique professors into the new table
___ ___ professors 
SELECT DISTINCT firstname, lastname, university_shortname 
FROM ___;

-- Doublecheck the contents of professors
SELECT * 
FROM ___;
Code bewerken en uitvoeren