Insert Data from one table to another leaving the already existing rows

SamuraiJack

Inserting data from one table to another is usually as simple as:

SELECT * INTO A FROM B

But just out of curiosity,suppose I have two tables tbl_A and tbl_B. I have 100 records in tbl_B and some 20 rows in tbl_A (some of which might be common in both tables), I want to insert rows from tbl_B into tbl_A which are not already present in tbl_A'

Also, lets assume that both table have identity fields.

Tim Schmelter

You can use NOT EXISTS:

INSERT INTO tbl_A 
    SELECT IdCol, Col2, Col3
    FROM dbo.tbl_B B
    WHERE NOT EXISTS(SELECT 1 FROM tbl_A A2 WHERE A2.IdCol = B.IdCol)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to insert specific columns and rows of data to an existing table from one table to another?

From Dev

Can i copy data from one database table to another already existing database table sql server?

From Dev

Select data from one table and insert into another existing table, which doesn't exist in the table

From Dev

Insert data from one table to another only if it doesn't already exist

From Dev

Transfer data from one table to another on insert

From Dev

Insert Data From One Table To Another - MySQL

From Dev

How to insert data from another table into an existing table, with an autoincrementing id?

From Dev

Insert many rows from a table into one unique row in another table

From Dev

Insert new rows into table but copy data from another row in the table

From Dev

select multiple column from one table and insert into another as rows

From Dev

Insert multiple rows with single a query from one table into another in Oracle

From Dev

Insert specific rows from one table in database into another with different columns

From Dev

Procedure to insert a data from one table to another table after calculations

From Dev

Insert Data From One Table to Another Table with default values

From Dev

Insert Data From One Table to Another Table and Add New Values

From Dev

insert data from one table to a single column another table with no relation

From Dev

MSSQL Insert Data From One Table To Another With Fixed Value

From Dev

INSERT data from one table to another where ids match

From Dev

Procedure to insert data from one column into two columns in another table

From Dev

Insert data from a table to another one in MySQL with where condition

From Dev

want to insert data from one table into another in php?

From Dev

insert data from one table to another - Not Working - possible bug?

From Dev

Adding rows from one table to another existing table where primary key is autogenerated

From Dev

Adding rows from one table to another existing table where primary key is autogenerated

From Dev

Inserting rows from one table into another if they don't already exist in MySQL

From Dev

Insert rows from one table to another but only those rows that have no duplicates

From Dev

Insert rows (if not already exist) to a already existing table (in MS-SQL / T-Sql)

From Dev

Entity framework code first - create table and insert data from existing table into newly created one,

From Dev

Entity framework code first - create table and insert data from existing table into newly created one,

Related Related

  1. 1

    How to insert specific columns and rows of data to an existing table from one table to another?

  2. 2

    Can i copy data from one database table to another already existing database table sql server?

  3. 3

    Select data from one table and insert into another existing table, which doesn't exist in the table

  4. 4

    Insert data from one table to another only if it doesn't already exist

  5. 5

    Transfer data from one table to another on insert

  6. 6

    Insert Data From One Table To Another - MySQL

  7. 7

    How to insert data from another table into an existing table, with an autoincrementing id?

  8. 8

    Insert many rows from a table into one unique row in another table

  9. 9

    Insert new rows into table but copy data from another row in the table

  10. 10

    select multiple column from one table and insert into another as rows

  11. 11

    Insert multiple rows with single a query from one table into another in Oracle

  12. 12

    Insert specific rows from one table in database into another with different columns

  13. 13

    Procedure to insert a data from one table to another table after calculations

  14. 14

    Insert Data From One Table to Another Table with default values

  15. 15

    Insert Data From One Table to Another Table and Add New Values

  16. 16

    insert data from one table to a single column another table with no relation

  17. 17

    MSSQL Insert Data From One Table To Another With Fixed Value

  18. 18

    INSERT data from one table to another where ids match

  19. 19

    Procedure to insert data from one column into two columns in another table

  20. 20

    Insert data from a table to another one in MySQL with where condition

  21. 21

    want to insert data from one table into another in php?

  22. 22

    insert data from one table to another - Not Working - possible bug?

  23. 23

    Adding rows from one table to another existing table where primary key is autogenerated

  24. 24

    Adding rows from one table to another existing table where primary key is autogenerated

  25. 25

    Inserting rows from one table into another if they don't already exist in MySQL

  26. 26

    Insert rows from one table to another but only those rows that have no duplicates

  27. 27

    Insert rows (if not already exist) to a already existing table (in MS-SQL / T-Sql)

  28. 28

    Entity framework code first - create table and insert data from existing table into newly created one,

  29. 29

    Entity framework code first - create table and insert data from existing table into newly created one,

HotTag

Archive