There are multiple SELECT statements, and multiple query results are returned as a single query result, and these combined queries are called and or compound queries
Usage: Returns similar structure data from different tables in a single query
Execute multiple queries against a single table, returning data as a single query
1 Create a combined query: Use the union operator to combine several SQL queries, and use union to give more than one select
Statements that combine their results into a single result set,
SELECT Id,name,price from Products WHERE Price <=5;
SELECT Id,name,price from Products WHERE ID in (1001,1002);
Select Id,name,price from Products where price <=5
UNION
SELECT id,name,price from products where ID in (1001,10 02);
Or
SELECT Id,name,price from the products WHERE the price <=5 OR ID in (1001,1002);
Rule: Each query must contain the same columns, expressions, or aggregate functions
The default repeating row is automatically canceled, and you want to return all matching rows, including the duplicate union ALL
2 sort, can only have one order by and not allow part one to sort another part by one sort
Select Id,name,price from Products where price <=5
UNION
SELECT id,name,price from products where ID in (1001,10 )
ORDER by Id,price;