How to use insert into statement

The creation of a new record in a table is done with the insert statement. Basically there are two ways to insert new records. The first one is by using the values subclause to specify the values for the columns of the new record like in:

create table Database_test_IB1.employee (
Emp_id integer,
last_name string, 
first_name string,
Starting_date date,
Salary numeric
);
insert into Database_test_IB1.employee
      (emp_id, last_name, first_name, starting_date, salary)
values  (101, 'Smith', 'John', '2021-06-01', 78000.00);

The other way to create new records in a table is by inserting a set of records, which are the result of a select SQL statement, like in:

insert into Database_test_IB1.employee
            select   emp_id, last_name, first_name, '2021-08-01'
            from     Database_test_IB1.candidates
            where    status = 'to be hired';

The previous insert can create many new records, however those new records will not have a defined value in the column emp_id and salary because these two columns are not included in the query.

IN THIS PAGE