---
title: "Efficient SQL Row Insertion Techniques"
description: "This post outlines two efficient ways to add rows to a table in SQL: direct insertion and insertion with a SELECT statement."
url: https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/
date: 2024-01-05
modified: 2025-07-04
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2024/01/pexels-photo-7365132.jpeg?fit=1880%2C1253&ssl=1
categories: ["SQL"]
tags: ["Insert into From Select"]
type: post
lang: en
---

# Efficient SQL Row Insertion Techniques

*Here are to methods add rows to a table in SQL. These include adding directly and with Select.*

Table of contents

1. [Insert Directly](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/#insert-directly)
2. [Insert with select](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/#selecting-values-from-a-table-and-inserting-into-a-new-table-1)
3. [Conclusion](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/#conclusion)

## Insert Directly

Example-1: SQL Query

```
INSERT INTO my_table (name, id, salary)
VALUES ('Srinimf', 1001, 150000);
```

When inserting data into a table, if the values are in sequence with the columns, you don’t need to specify the column names. However, if the values don’t match the column sequence, you must provide the column names. The columns for which you haven’t inserted any values will have their default values, such as NULL. All [NOT NULL columns](https://srinimf.com/2020/02/10/how-to-use-not-null-constraint-correctly/) you must supply values.

**Audio explanation**

*Insert and Select*

## Insert with select

Here, from the select statement, you’ll get the data, and the same you can insert into new table.

1. INSERT INTO
2. SELECT

Example-2: SQL Query

Ensure that you should be created NEW_TABLE with the same columns before you copy the data.

```
INSERT INTO NEW_TABLE ( name, id, salary)
SELECT name, id, salary 
from MY_TABLE
WHERE id = 1001;
```

After executing the SQL query, the data from the MY_TABLE will be inserted into the NEW_TABLE. You can then view the data in the NEW_TABLE. This example is designed for use with DB2.

The following screen shows my testing of this SQL query.

![SQL Query Result](https://i0.wp.com/srinimf.com/wp-content/uploads/2023/11/image.png?resize=956%2C544&ssl=1)*The result*

## Conclusion

The given SQL queries demonstrate how to insert values into a table and select values from another table in a single query. These examples illustrate the use of INSERT INTO and SELECT statements to accomplish this task efficiently. It’s important to ensure that the new table has the same columns before copying the data, and to handle any mismatches between the values and column sequence appropriately. Overall, these methods provide a streamlined approach to data manipulation in SQL.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2024%2F01%2F05%2Fsql-ideas-on-how-to-insert-using-select%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2024%2F01%2Fpexels-photo-7365132.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Efficient%20SQL%20Row%20Insertion%20Techniques)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2024/01/05/sql-ideas-on-how-to-insert-using-select/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Efficient%20SQL%20Row%20Insertion%20Techniques&body=https%3A%2F%2Fsrinimf.com%2F2024%2F01%2F05%2Fsql-ideas-on-how-to-insert-using-select%2F&share=email)
-

### Like this:

Like Loading…
