Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql federated query statement how to write this

Shulou Source: shulou.com Published: 2022-05-31 23:58:28 11月15日 Update

This article mainly introduces the mysql joint query sentence how to write, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The mysql joint query statement is [query statement 1 union query statement 2], which requires the type and best consistency of each column of the query with multiple query statements. The union keyword is deduplicated by default, and duplicates can be included if union all is used.

Joint query

UNION federated merge: merges the results of multiple query statements into a single result

Syntax:

Query statement 1union query statement 2

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 of each column of a query that requires multiple query statements is best consistent.

3. The union keyword is deduplicated by default, and duplicates can be included if you use union all

Introduced case: query department number > 90 or mailbox contains employee information of a

SELECT * FROM employeesWHERE email like'% a%'or department_id > 90SELECT * FROM employeesWHERE email like'% a%'UNIONSELECT * FROM employeeswhere department_id > 90

Case study: query information about men in Chinese users and men in foreign users

Thank you for reading this article carefully. I hope the article "how to write mysql Joint query sentence" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Queries statements federation consistency information multiple articles results keywords multiple best case user male type value interest and at the same time employees Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn macOS Huawei Xiaomi