Populate the "professor_id" column
Now it's time to also populate professors_id. You'll take the ID directly from professors.
Here's a way to update columns of a table based on values in another table:
UPDATE table_a
SET column_to_update = table_b.column_to_update_from
FROM table_b
WHERE condition1 AND condition2 AND ...;
This query does the following:
- For each row in
table_a, find the corresponding row intable_bwherecondition1,condition2, etc., are met. - Set the value of
column_to_updateto the value ofcolumn_to_update_from(from that corresponding row).
The conditions usually compare other columns of both tables, e.g. table_a.some_column = table_b.some_column. Of course, this query only makes sense if there is only one matching row in table_b.
Questo esercizio fa parte del corso
Introduction to Relational Databases in SQL
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
-- Have a look at the 10 first rows of affiliations
___;