Use connection (join) instead of subquery (sub-queries)
MySQL supports SQL subquery starting from 4.1. This technique can use the SELECT statement to create a single-column query result, and then use the result as a filter for another query. For example, if we want to delete a customer who does not have any orders in the customer's basic information table, we can take advantage of the subquery to remove all the customer IDs from the Sales Information table and then pass the results to the main query, as follows:
DELETE from WHERE not in (theSELECT from
The use of subqueries allows you to do a lot of SQL operations that logically require multiple steps to complete, as well as to avoid transactions or table locks and write them easily. However, in some cases, subqueries can be more efficiently connected (join). Alternative. For example, suppose we want to take out all the users without an order record, which can be done with the following query:
SELECT * from WHERE not in (theSELECT from
If you use Connection (join): To complete this query work, the speed will be much faster. Especially if the Salesinfo table in the CustomerID index, the performance will be better, query as follows:
SELECT * from leftjoins on CustomerInfo. CustomerID=WHEREisNULL
Connect (Join): It is more efficient because MySQL does not need to create a temporary table in memory to complete this logical two-step query effort
Use connection (join) to replace subquery (sub-queries) MySQL optimization series record