Back to Mysql database theory and practice

# Advanced 10: Merge query (join query) Introduction: a result set query has data from multiple tables. But there is no correlation between the tables.

Select * from table 1 union select * from table 2 union… Select list from table n Features: ① The number of columns in the query statement that implements union must be the same. There is no requirement for column names or column meanings. ② The default implementation of union is de-query. If you don’t want to deduplicate, use union all

SELECT id id, cname name, cgender FROM Chinese UNION SELECT uid,uname,uname FROM USA; # Case 2: SELECT 1,100,' triple 'UNION ALL SELECT 1,100,' triple' UNION ALL SELECT 1,100 1,100,' three '# single table joint query # Case 3: SELECT * FROM employees WHERE last_name LIKE '%a%' or salary>10000 or SELECT * FROM employees WHERE last_name LIKE '%a%' or salary>10000 or department_id<120 OR commission_pct IS NOT NULL; SELECT * FROM employees WHERE last_name LIKE '%a%' UNION SELECT * FROM employees WHERE salary > 10000 UNION SELECT  * FROM employees WHERE department_id<120 UNION SELECT * FROM employees WHERE commission_pct IS NOT NULL;Copy the code