Table inserts are very common when you are a SQL developer or Data analysis specialist. In this post, I have explained some ideas on inserting values using SELECT.
To insert data you need three key statements:
- INSERT
- INTO
- VALUES
Sample SQL Query
INSERT INTO my_table (name, id, salary)
VALUES ('Srinimf', 1001, 150000);
While inserting, if you know the values are in sequence to columns then not needed to give column names else you need to give.
The remaining columns when you not inserted the values will have their default values – Like NULL.
All NOT NULL columns you must supply values.
In the above example, I have not used SELECT.
How to INSERT values using SELECT
This concept also called cross checking. That means after INSERT you can get the data inserted.
The Key Statements you need
- SELECT
- NEW TABLE
- INSERT
- INTO
- VALUES
Example SQL Query
SELECT * FROM NEW_TABLE (
INSERT INTO my_table (name, id, salary)
VALUES ('Srinimf', 1001, 150000)
);
From the above Query you can get the data after inserting values. This example would work well in DB2.
Related Posts