MySQL self-Connection learning notes

Source: Internet
Author: User

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.

/tbody>
  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 '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.