In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you how to merge mysql query results, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
In mysql, you can merge query results using the UNION operator, which is used to merge the query results of more than two SELECT statements together and then remove the same records; syntax "query statement 1 union query statement 2 union."
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In mysql, you can use the UNION operator to merge query results.
The UNION operator is used to join the results of more than two SELECT statements into a result set. Multiple SELECT statements delete duplicate data.
Syntax:
Query statement 1union query statement 2Union.
Application scenarios:
When the result of the query comes from multiple tables, and the multiple tables are not directly connected, but the information of the query is the same.
Features: ★
1. The number of query columns of multiple query statements is required to be the same!
2. The type and order of each column of a query requiring multiple query statements should be the same.
3. The union keyword is deduplicated by default, and duplicates can be included if you use union all
Example: query department number > 90 or mailbox contains employee information of a
Next, I will directly po screenshots and code.
# Joint query # SELECT * FROM employees WHERE department_id > 90 OR email LIKE'% a% leaders # use UNION to jointly query SELECT * FROM employees WHERE department_id > 90UNIONSELECT * FROM employees WHERE email LIKE'% a% alternative use test # case: query the information of women in Chinese users and the information of women in foreign users SELECT c.`c _ name`, c.`c _ sex` FROM china c WHERE c_sex = 'female' UNIONSELECT f.`f _ id`, f.`f _ name`, f.`f _ sex` FROM foreignUser f WHERE f_sex = 'female' # both china table and foreignUser table have number 66 Han Meimei (UNION will remove duplicates) SELECT c.`c _ name` FROM china c WHERE c_sex = 'female' UNIONSELECT f.`f _ id`, f.`f _ name` FROM foreignUser f WHERE f_sex = 'female' # both china table and foreignUser table have number 66 Han Meimei (UNION ALL will not be duplicated) SELECT c.`c _ name` FROM china c WHERE c_sex = 'female' UNION ALLSELECT f.`f _ id`, f.`f _ name` FROM foreignUser f WHERE f_sex = 'female'
Use UNION
Use UNION ALL
About how to merge the mysql query results to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can 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.