Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy row from a table to another table if the entry is not exist in the new table in sql [closed]

Tags:

sql

copy

I need to copy all data from a table to an another same schema table. If the new table has a row already then i need not to update or insert it. I need only new data from old table that does not exist in new table to copy to that new table.

So what will be the sql query, can any one help me.

Thanks, Muntasir Rahman Rafi

like image 737
raficsedu Avatar asked Jul 09 '13 05:07

raficsedu


People also ask

How can I get data from one table not present in another table in SQL?

How to Select All Records from One Table That Do Not Exist in Another Table in SQL? We can get the records in one table that doesn't exist in another table by using NOT IN or NOT EXISTS with the subqueries including the other table in the subqueries.

How do I copy a row from one table to another in SQL?

Using SQL Server Management StudioOpen the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design. Click the tab for the table with the columns you want to copy and select those columns. From the Edit menu, click Copy.

How do you select all records from one table that do not exist in another table in Excel?

select [ selecting columns] From table1 Right OUTER JOIN table2 ON(table1. SQL> select e. select [ selecting columns] From table1 Right OUTER JOIN table2 ON(table1. select column_name from table 1 full outer join table 2 on(connection); here all the data from table 1 and table 2 will get retrieved.


1 Answers

try this :

INSERT INTO TABLENAME2 (col1, Col2, col3)
SELECT *
FROM tablename1 A
WHERE NOT EXISTS (
          SELECT *
          FROM tablename2 B
          WHERE A.col1 = B.col1
     )
like image 59
Ahmed Avatar answered Nov 15 '22 04:11

Ahmed