In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces SQL how to insert data in a table into another table of related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this SQL how to insert data in a table into another table the article will have a harvest, let's take a look at it.
Create a test table MyStudentInfoCREATE table MyStudentInfo (Id int not null primary key, Name varchar (16), Age int, Gender varchar (2), Phone varchar (16), Address varchar (50), GradeId int) to insert multiple pieces of data, INSERT INTO MyStudentInfoSELECT 1, Zhang San, 20, and 1 UNIONSELECT 2, Li Si, 22, 12345678901, Wang Wu, 13976891234, 13976891234, respectively. 'Tianjin', 2 UNIONSELECT 4, Zhao Liu, 19 UNIONSELECT, 18676891234, 18676891234, 3 UNIONSELECT 5, Xiaohong, 21, 17776891234, 4 UNIONSELECT 6, Wang, 25, 13176891234, 2 UNIONSELECT, 7 Liu, 13374591234, 13374591234, Nanjing, 1, one, one, and one sentence selects data from a table. Then insert the data into another table
1. Insert all the field data of the MyStudentInfo table into a table that does not exist
SELECT * INTO studentinfo_test1 FROM MyStudentInfo
2. Insert individual field data of the MyStudentInfo table into a table that does not exist.
SELECT Id,Name INTO MytestInfo FROM myStudentInfo
3. With where clause
SELECT Id,Name,Gender INTO MytestInfo FROM myStudentInfo WHERE Gender='1'
Query the data of MytestInfo table
4. Select data from more than one table to insert into the new table
SELECT s.Id,s.Name,s.GradeId,g.GradeName INTO NewTable FROM MyStudentInfo s INNER JOIN GradeInfo g on s.GradeId=g.Id
Query the data of NewTable table
Insert the data in the studentinfo table into the existing table
Insert the id,name column of the MyStudentInfo table into the studentinfo_test2 (studentinfo_ Test2 table already exists)
INSERT INTO studentinfo_test2SELECT * FROM MyStudentInfo's article on "how SQL inserts data from one table into another" ends here. Thank you for reading! I believe that everyone has a certain understanding of "how SQL inserts data from one table into another". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.