In our work, we often need to write query statements. Left join and right join are common associations in query statements. But when we use them, have we ever thought about how to associate them and how to select their order?
For example, if Table A is associated with table B, table A must also be associated with table C. If table A is associated with table B, A and table B may have a null value or null value, A and C cannot have null values, so let's first think about how to deal with them?
You may say this is not easy, as shown below:
Implementation 1:
Select * from C inner join
On C. ID = A. ID
Left join B
On a. Code = B. Code
Implementation 2:
Select * from a left join B
On a. Code = B. Code
Inner join C
On a. ID = C. ID
Implementation 3:
Select * from B right join
On a. Code = B. Code
Inner join C
On a. ID = C. ID
Which of the three methods is listed at will, is it always better?
According to the current situation, if the data volume is the same as that at the time, first join inner and then
Left join and right join provide query efficiency.
However, it depends on the actual situation. Generally, we will give priority to implementation 1.