MySQL operation details and good habits -------- updating..., -------- updating
1. Try not to write too complex SQL queries, and do not think about returning all the results in the form required by the previous end at a time. You can separate the queries multiple times so that the logic is clear, fast problem solving, easy maintenance, and high SQL efficiency.
2. When you use a join Table query, the length of the joined table must not be too long. Otherwise, the query efficiency will be greatly affected. The actual situation at work is that when the length of the joined table is close to 1000, the speed will decrease significantly.
3. About group:
- After grouping BY, the result is aggregated into a "GROUP". It is mostly used to remove duplicates or return statistics from different groups, such as the maximum value or something. That is, only one value in the same GROUP of data is returned, it can be used with group_contact to connect multiple data of the same field and return it as a field. If you need to return all the data in different groups, you cannot use group by (group by didn't do well at the beginning ...)
- Group by x means to put all records with the same X field value in a GROUP.
- Group by x, Y means to put all records with the same X field value and Y field value into a GROUP.