Home >Backend Development >PHP Tutorial >In Thinkphp, should I use in ids or left join for mysql two-table query (in the case of paging, the ids array is usually about 20)?
I don’t know which solution is better
I read in the book that it is usually a split-table query, which is good for caching
I don’t know which solution is better
I read in the book that it is usually a split-table query, which is good for caching
It mainly depends on the amount of data and application scenarios. When the amount of data is small, the two are almost the same
Which one is more efficient: where in() query or multi-table left join joint query?
You are talking about a SQL problem. People who use left join far outnumber those who use in.
The usage scenarios of these two syntaxes are different. In knows the ID to filter out the records that match your ID group, while left join is a related table. If I are doing paging, I will check whether the associated table is a large table (hundreds of thousands or millions of records), and then decide whether to use left join. Even if I use join, it is best to explain it and see if it is optimal. No. If so, take a look at the explain results and optimize it. It is recommended not to join for very large tables; if you use in, there should be no multiple loops when extracting IDs and querying the secondary table to assemble the data into the main table data set, and the efficiency will not necessarily be that slow.