SQL tutorial 34: How to copy /Insert data into a table from another table using INSERT INTO SELECT

Manish Sharma · Beginner ·🛠️ AI Tools & Apps ·11y ago

Key Takeaways

Copies data from one table to another using SQL INSERT INTO SELECT statement

Full Transcript

what's up internet I'm Manish from rebellionrider.com and I'm back once again with another SQL tutorial and in today's tutorial we will learn how to insert or copy data from one table to another using SQL insert into statement or say insert into select a statement in the previous tutorial we have seen how to insert data into a table using SQL Developer as well as using insert DML statement today we will see the Third Way of inserting data into a table without Much Ado let's jump over SQL Developer and start writing cury as you know we have a student table which we have created and used in the previous tutorial and I have populated this table with some data let me show you this student table will be our source table whose data we are going to copy into a Target table now we need this target table this target table should have same structure as that of student table to save the time I have already created this target table by the name of student copy and for the sake of Simplicity there are no constant on any column of this table let me show you the structure of student copy Target table and as you can see this table is empty this whole process of copying rows from one table to another involves only one simple insert into C let's see how to write this there is no need to be intimidated by this little bit of subury concept involved here I'll be doing a separate tutorial on subquery don't worry for now here in this cury we are inserting the entire data of table student which is our source table into table student copy which is our Target table for the better understanding of this concept let's make some space between these two lines now you people can see things clearly as you can see this query is a combination of two queries in the first half of this query we have our insert DML statement followed by name of Target table student copy and in the second half we have a simple select statement where we are selecting entire data from Source table student before execution let me adjust the SQL Developer IDE so that I can show you the execution side by side okay everything is set now as you can see targetable student copy is entirely empty now let's execute our cury four rows inserted okay let's refresh here is our result isn't it simple entire data of the source table student is copied into the target table student copy let's do our second query but first let me close this output panel so that I can make some space and you people can see what I'm going to do next okay I think everything is set now now in our second query we will see how to insert selected data into a table from another table but before writing this query I will remove entire data from the target table student copy so that you can better understand the concept say this time you just want to insert data from column first name and last name of source table student into Target table student copy okay let me make some space now I think C is clearly visible to you guys okay let's move ahead this cury is slightly different from the previous Cy whenever we insert data into some selected Columns of a table we have to mention those column in the insert cery right after name of Target table as we did here as you can see right after the name of Target table student copy I have specified the name of column in which I want to insert the data and in our case it's first name and last name mind here do not to forget and close the list of column name in parenthesis otherwise SQL compiler will give you an error after that we have our selected statement this statement will return return first name and last name which we want to insert let's execute the query now refresh here and here we go as you can see in the result all the value in is2 ID and contact column is null there are values only in first and last name column what happened with this query is that the output of selected statement becomes the input of the inserted statement let's take the example of this query here our selected statement is returning value from first and last name column which is its output the output becomes the input offers insert cury furthermore there is one-on-one mapping between the column in this list this means means that value from the first column in the select list gets copied into the corresponding First Column you mention in the insert list hope this query is clear let's jump on the third cury once again let me close this script output now let's write the third cury similarly you can use we Clause to copy the data from one table to another but once again let's delete all the data from the table okay everything is set say now you want to copy only that Row from the student table where true ID is five let's execute it says zero rules inserted means let me check okay we do not have any fifth row in our source table student so so what we will do we will change this five from four let's copy the data of a student where 2 ID is 4 let me check who is there student with 2 ID 4 is Batman with 45678 contact number okay oh sorry yes our Target table student copy doesn't have anything so now let's execute this query one row inserted so now let's refresh here is our result hope you enjoyed watching that's it for today there is no reason of making videos if you don't like the content which I am producing so please hit the thumbs up button and keep me motivated comment your feedback and please don't forget to subscribe take care this is Manish

Original Description

How To copy or Insert data from one table to another Inserting data into a table from another table Tutorial Consist: How to copy entire data from one table to another. How to copy selected data using column name and How to copy selected data using WHERE clause How to use INSERT INTO SELECT statement with WHERE Clause Links tut 32 Insert Using SQL Developer http://youtu.be/YYQCSV6MzTk Tut 33 Insert Using INSERT DML : http://youtu.be/uQXgqFtxI_k Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage https://copy.com?r=kb4rc1 Amazon Wishlist: http://bit.ly/wishlist-amazon Contacts E-Mail RebellionRiderYT@gmail.com Twitter https://twitter.com/rebellionrider Instagram http://instagram.com/rebellionrider Facebook. https://www.facebook.com/imthebhardwaj Linkedin. http://in.linkedin.com/in/mannbhardwaj/ Thanks for liking, commenting, sharing and watching more of our videos This is Manish from RebellionRider.com
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Manish Sharma · Manish Sharma · 40 of 60

1 Oracle Database tutorials 1: How to install Oracle Database 11g on windows 7
Oracle Database tutorials 1: How to install Oracle Database 11g on windows 7
Manish Sharma
2 Oracle Database tutorials 2:How To install SQL Developer on windows 7
Oracle Database tutorials 2:How To install SQL Developer on windows 7
Manish Sharma
3 Oracle Database tutorials 3:How to enable Line numbers in SQL Developer.
Oracle Database tutorials 3:How to enable Line numbers in SQL Developer.
Manish Sharma
4 Oracle Database tutorials 4:  database connectivity using SQL developer and command prompt
Oracle Database tutorials 4: database connectivity using SQL developer and command prompt
Manish Sharma
5 Oracle Database tutorials 5:  how to Fetch Data using SELECT - SQL statement by Manish Sharma
Oracle Database tutorials 5: how to Fetch Data using SELECT - SQL statement by Manish Sharma
Manish Sharma
6 Oracle Database11g tutorials 6 | | How to use Concatenation operator, character String
Oracle Database11g tutorials 6 | | How to use Concatenation operator, character String
Manish Sharma
7 Oracle Database11g tutorials 7 | |SQL DISTINCT keyword || SQL tutorials
Oracle Database11g tutorials 7 | |SQL DISTINCT keyword || SQL tutorials
Manish Sharma
8 Canon EOS 600D 2 lens kit/Canon rebell EOS T3i 2 lens kit Unboxing
Canon EOS 600D 2 lens kit/Canon rebell EOS T3i 2 lens kit Unboxing
Manish Sharma
9 First look: ORACLE CERTIFIED ASSOCIATE (OCA) CERTIFICATE  - ORACLE DATABASE ADMINISTRATOR
First look: ORACLE CERTIFIED ASSOCIATE (OCA) CERTIFICATE - ORACLE DATABASE ADMINISTRATOR
Manish Sharma
10 Oracle Database11g tutorials 8 || SQL DISTINCT with multiple columns |SQL Distinct with Two columns
Oracle Database11g tutorials 8 || SQL DISTINCT with multiple columns |SQL Distinct with Two columns
Manish Sharma
11 Oracle Database11g tutorials 9 || What is archive log mode and how to enable archive log mode
Oracle Database11g tutorials 9 || What is archive log mode and how to enable archive log mode
Manish Sharma
12 Oracle Database11g tutorials 10 ||  SQL Single Row Function (SQL Functions )
Oracle Database11g tutorials 10 || SQL Single Row Function (SQL Functions )
Manish Sharma
13 Oracle Database11g tutorials 11: SQL case manipulation function in Oracle Database
Oracle Database11g tutorials 11: SQL case manipulation function in Oracle Database
Manish Sharma
14 how to add channel trailer and section on your youtube channel 2014
how to add channel trailer and section on your youtube channel 2014
Manish Sharma
15 Oracle Database11g tutorials 12 || SQL Concat Function - SQL character manipulation function
Oracle Database11g tutorials 12 || SQL Concat Function - SQL character manipulation function
Manish Sharma
16 Oracle Database11g tutorials 13 || SQL substr function / SQL substring function
Oracle Database11g tutorials 13 || SQL substr function / SQL substring function
Manish Sharma
17 Oracle Database11g tutorials 14 : How to CREATE TABLE using sql developer and command prompt
Oracle Database11g tutorials 14 : How to CREATE TABLE using sql developer and command prompt
Manish Sharma
18 SQL tutorials 15 || How To CREATE TABLE using enterprise manager 11g
SQL tutorials 15 || How To CREATE TABLE using enterprise manager 11g
Manish Sharma
19 Oracle Database11g tutorials 16: How to uninstall oracle 11g from windows 7 64 bit
Oracle Database11g tutorials 16: How to uninstall oracle 11g from windows 7 64 bit
Manish Sharma
20 ORACLE CERTIFIED PROFESSIONAL(OCP) CERTIFICATE First look  - ORACLE DATABASE ADMINISTRATOR
ORACLE CERTIFIED PROFESSIONAL(OCP) CERTIFICATE First look - ORACLE DATABASE ADMINISTRATOR
Manish Sharma
21 Plantronics audio 655 USB headset with Mic Unboxing and Review and Plantronics audio 655 Mic test
Plantronics audio 655 USB headset with Mic Unboxing and Review and Plantronics audio 655 Mic test
Manish Sharma
22 SQL tutorials 17: SQL Primary Key constraint,  Drop primary Key
SQL tutorials 17: SQL Primary Key constraint, Drop primary Key
Manish Sharma
23 SQL tutorials 18: SQL Foreign Key Constraint By Manish Sharma
SQL tutorials 18: SQL Foreign Key Constraint By Manish Sharma
Manish Sharma
24 SQL tutorial 19: ON DELETE SET NULL clause of Foreign Key By Manish Sharma (RebellionRider)
SQL tutorial 19: ON DELETE SET NULL clause of Foreign Key By Manish Sharma (RebellionRider)
Manish Sharma
25 SQL tutorials 20: On Delete Cascade Foreign Key By Manish Sharma (RebellionRider)
SQL tutorials 20: On Delete Cascade Foreign Key By Manish Sharma (RebellionRider)
Manish Sharma
26 SQL tutorial 21: How To Rename Table in SQL using ALTER TABLE statement By Manish Sharma
SQL tutorial 21: How To Rename Table in SQL using ALTER TABLE statement By Manish Sharma
Manish Sharma
27 SQL tutorial 22: How to Add / Delete column from an existing table using alter table
SQL tutorial 22: How to Add / Delete column from an existing table using alter table
Manish Sharma
28 SQL tutorial 23: Rename and Modify Column Using Alter Table By Manish Sharma (RebellionRider)
SQL tutorial 23: Rename and Modify Column Using Alter Table By Manish Sharma (RebellionRider)
Manish Sharma
29 SQL tutorial 24 :SQLJoins- Natural Join With ON and USING clause By Manish/Rebellionrider
SQL tutorial 24 :SQLJoins- Natural Join With ON and USING clause By Manish/Rebellionrider
Manish Sharma
30 Oracle Database11g tutorials 25: How to install Oracle Database 11g Express Edition R2 on Windows 7
Oracle Database11g tutorials 25: How to install Oracle Database 11g Express Edition R2 on Windows 7
Manish Sharma
31 SQL tutorial 26: Introduction to SQL Joins in Oracle Database
SQL tutorial 26: Introduction to SQL Joins in Oracle Database
Manish Sharma
32 Vidcon 2014 YouTube Fan Funding: How to enable fan funding on YouTube Channel
Vidcon 2014 YouTube Fan Funding: How to enable fan funding on YouTube Channel
Manish Sharma
33 SQL tutorial 27: Right Outer Join in SQL by Manish Sharma for RebellionRider
SQL tutorial 27: Right Outer Join in SQL by Manish Sharma for RebellionRider
Manish Sharma
34 SQL tutorial 28: Left Outer Join By Manish Sharma / RebellionRider
SQL tutorial 28: Left Outer Join By Manish Sharma / RebellionRider
Manish Sharma
35 SQL tutorial 29: Full Outer Join with example By Manish Sharma/ RebellionRider
SQL tutorial 29: Full Outer Join with example By Manish Sharma/ RebellionRider
Manish Sharma
36 SQL tutorial 30: Inner Join In SQL by Manish Sharma/RebellionRider
SQL tutorial 30: Inner Join In SQL by Manish Sharma/RebellionRider
Manish Sharma
37 SQL tutorial 31 : SQL Cross Join In Oracle Database By Manish Sharma from RebellionRider
SQL tutorial 31 : SQL Cross Join In Oracle Database By Manish Sharma from RebellionRider
Manish Sharma
38 SQL tutorial 32: How To Insert Data into a Table Using SQL Developer
SQL tutorial 32: How To Insert Data into a Table Using SQL Developer
Manish Sharma
39 SQL tutorial 33:How To Insert Data into a Table Using SQL INSERT INTO dml statement
SQL tutorial 33:How To Insert Data into a Table Using SQL INSERT INTO dml statement
Manish Sharma
SQL tutorial 34: How to copy /Insert data into a table from another table using INSERT INTO SELECT
SQL tutorial 34: How to copy /Insert data into a table from another table using INSERT INTO SELECT
Manish Sharma
41 SQL tutorial 35: DELETE and TRUNCATE how to delete data from a table
SQL tutorial 35: DELETE and TRUNCATE how to delete data from a table
Manish Sharma
42 SQL tutorial 36: how to create database using database configuration assistant DBCA
SQL tutorial 36: how to create database using database configuration assistant DBCA
Manish Sharma
43 SQL tutorial 37: How to create NEW USER account using Create User statement in Oracle database
SQL tutorial 37: How to create NEW USER account using Create User statement in Oracle database
Manish Sharma
44 SQL tutorial 38: How to create user using SQL Developer in Oracle database
SQL tutorial 38: How to create user using SQL Developer in Oracle database
Manish Sharma
45 SQL tutorial 39: How to create user in oracle using Enterprise Manager
SQL tutorial 39: How to create user in oracle using Enterprise Manager
Manish Sharma
46 SQL tutorial 40: DBA Trick, How to drop a user when it is connected to the database
SQL tutorial 40: DBA Trick, How to drop a user when it is connected to the database
Manish Sharma
47 Motorola Moto G 2nd Generation / G2 Unboxing and Review
Motorola Moto G 2nd Generation / G2 Unboxing and Review
Manish Sharma
48 SQL tutorial 41: How to UNLOCK USER in oracle Database
SQL tutorial 41: How to UNLOCK USER in oracle Database
Manish Sharma
49 SQL tutorial 42: How to Unlock user using SQL Developer By Manish Sharma RebellionRider
SQL tutorial 42: How to Unlock user using SQL Developer By Manish Sharma RebellionRider
Manish Sharma
50 SQL tutorial 43: How to create an EXTERNAL USER in oracle database By Manish Sharma RebellionRider
SQL tutorial 43: How to create an EXTERNAL USER in oracle database By Manish Sharma RebellionRider
Manish Sharma
51 SQL tutorial 44: How to import data from Microsoft Excel to Oracle Database using SQL Developer
SQL tutorial 44: How to import data from Microsoft Excel to Oracle Database using SQL Developer
Manish Sharma
52 SQL tutorial 45: Introduction to user Privileges in Oracle Database By Manish Sharma RebellionRider
SQL tutorial 45: Introduction to user Privileges in Oracle Database By Manish Sharma RebellionRider
Manish Sharma
53 SQL tutorial 46: What are System Privileges & How To Grant them using Data Control Language
SQL tutorial 46: What are System Privileges & How To Grant them using Data Control Language
Manish Sharma
54 SQL tutorial 47: How to Grant Object Privileges With Grant Option in Oracle Database
SQL tutorial 47: How to Grant Object Privileges With Grant Option in Oracle Database
Manish Sharma
55 SQL tutorial 48: How to create Roles in Oracle Database
SQL tutorial 48: How to create Roles in Oracle Database
Manish Sharma
56 SQL tutorial 49: CASE - Simple Case Expression in Oracle Database (1/2)
SQL tutorial 49: CASE - Simple Case Expression in Oracle Database (1/2)
Manish Sharma
57 SQL tutorial 50: CASE - Searched Case Expression In Oracle (2/2)
SQL tutorial 50: CASE - Searched Case Expression In Oracle (2/2)
Manish Sharma
58 SQL tutorial 51: DECODE function in Oracle Database By Manish Sharma (RebellionRider)
SQL tutorial 51: DECODE function in Oracle Database By Manish Sharma (RebellionRider)
Manish Sharma
59 Oracle Database Tutorial 52 : Data Pump expdp - How to Export full database using expdp
Oracle Database Tutorial 52 : Data Pump expdp - How to Export full database using expdp
Manish Sharma
60 Oracle Database Tutorial 53 : Data pump expdp - How to Export tablespace in Oracle Database
Oracle Database Tutorial 53 : Data pump expdp - How to Export tablespace in Oracle Database
Manish Sharma

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →