Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting and updating NULLs
Conditions in UPDATE and DELETE
Updating the list of columns in one query
Using values from another column
Return rows in INSERT, UPDATE, DELETE
16. Display inserted values
Summary

Instruction

Excellent! You know how to display column values during a DELETE operation. You can do the same thing during an INSERT:

INSERT INTO student VALUES
(13, 'Alan', NULL, 'Stanley')
RETURNING id, last_name;

This returns a table with the specified column names and the inserted values:

id last_name
13 Stanley

Notice that the RETURNING clause is placed at the end of the query. After RETURNING, we list the names of the columns where the data is being inserted. Column names are separated by commas (id, last_name).

As in the DELETE statement, RETURNING will display selected data or all inserted data. In the example above, we only show data from two columns from the inserted row.

Exercise

Are you ready to do a task on your own? The teacher would like to insert Alan Stanley's score on his written Spanish exam. Alan's student ID is 13, he scored 23 points, the exam date was 2018-06-23, and the exam score date was 2018-06-30. The ID of the exam is 16.

Show the exam score and the score date for the inserted records.