In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the example analysis about the empty id of the implementation plan in mysql. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Brief introduction
The UNION operator is used to merge the result sets of two or more SELECT statements. For example, I have two tables. Table 1 records the data of the company's male employees, including age, name and position. Table 2 records the data of female employees of the company, including name, home address, mobile phone number and other fields. At this point, we want to query the collection of the names of the two tables according to certain conditions. The UNION keyword is used.
UNION can query multiple fields, but the SELECT statement must have the same number of columns. Columns must also have similar data types. At the same time, the columns in each SELECT statement must be in the same order.
Grammar
SELECT column_name (s) FROM table_name1 UNION SELECT column_name (s) FROM table_name2
The UNION operator deduplicates the result set. If duplicate values are allowed, you can use UNION ALL to make no difference between the two except for repetitive functions.
Example
For the example here, take the introduction in the introduction as the requirement, create two tables, and operate accordingly.
First, create two user1,user2 tables with the following statements:
CREATE TABLE user1 (id INT, age INT, NAME VARCHAR (5), position VARCHAR (8)); CREATE TABLE user2 (id INT, name VARCHAR (5), address VARCHAR (50), phone_number VARCHAR (20))
Secondly, insert the corresponding data. The sql is as follows:
-- data insertion statements INSERT INTO user1VALUES (1,20, 'Zhang San', 'Technical Supervisor'); INSERT INTO user1VALUES (2,20,'Li Si', 'Product Supervisor'); INSERT INTO user1VALUES (3,20, Wang Wu, 'Operations Supervisor') INSERT INTO user1VALUES (4,20, 'Zhao Liu', 'logistics supervisor') INSERT INTO user2 (id, NAME, address, phone_number) VALUES (1, 'Zhenzhen', 'Beijing', '155332211'); INSERT INTO user2 (id, NAME, address, phone_number) VALUES (2, 'Lianlian', 'Shanghai', '155332211') INSERT INTO user2 (id, NAME, address, phone_number) VALUES (3, 'Love', 'Shenzhen', '155332211')
Finally, run the UNION statement to make the query
-- UNION statement SELECT NAME FROM user1 UNION SELECT name FROM user2
After the code is executed, the result is as follows:
The column name in the result set here is the column name of the first select statement of the UNION statement (user1 is NAME, user2 is name).
When explain, id is null
When the execution plan of UNION is executed, the execution id of the last merge result set operation is null. Furthermore, the first select_type executed is a simple query, the second and subsequent queries are UNION, and the final merge select_type is UNION RESULT.
The execution plan code is as follows:
EXPLAIN SELECT NAME FROM user1UNIONSELECT name FROM user2
The results are as follows:
This is the end of the article on "sample Analysis of empty id in mysql". I hope the above content can be of some help to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.