MySQL's Self connection processing speed is much faster than subquery. So it is necessary to learn from the connection.
Normal SQL subquery statement
| The code is as follows |
Copy Code |
Select ' id ', ' bic ' from ' Biao ' where ' id ' = (select ' id ' from ' biao ' where ' id ' = ' 9696e '); |
MySQL's self-connected SQL statement
| The code is as follows |
Copy Code |
SELECT ' id ', ' bic ' from ' Biao ' as a, ' Biao ' as B WHERE a.id=b.id and b.id= ' www.111cn.net '; |
The self-contained SQL statement also looks refreshing and graceful.
From these two examples, we can see that the grammatical structure of the self connection is very simple, but the semantic result is often not
So easy to understand. The two tables listed here, if applied properly, can solve many practical problems,
For example, how to transfer between any two sites.
| code is as follows |
copy code |
| SELECT R1.company, R1.num from Route R1, Route R2, stops S1, stops S2 WHERE r1.num=r2.num and R1.company=r2.company and R1.stop=s1.id and r2.stop=s2.id and s1.name= ' Craiglockhart ' and s2.name= ' Tollcross ' |
/tbody>