SQL self-connection-Example: querying the first course of the first course

Source: Internet
Author: User

There is a course table with course No. (CNO), course name (cname), and first course No. (pcno)

Now I want to query the first course of each course. Solution (self-connection ):

Consider the Course table as A and B. In this way, it is equivalent to connecting two tables. The control condition is that the course number in Table A is equal to the first course number in table B. The course number in Table A is the "grandpa" of the course number in Table B, that is, the first course.

SQLCode: Select a. CNO, A. cname, B. pcno
From course A, course B
Where a. pcno = B. CNO

 

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.