SQL Advanced Query Tips (two joins in the same table, self-contained joins, unequal joins)

Source: Internet
Author: User
Tags joins

Master these, it's more advanced.

Using the same Table twice

such as the Branch field in the following query

SELECTa.account_id, e.emp_id, B_a.name open_branch, B_e.name emp_branch fromAccount asAINNER JOINBranch asB_a ona.open_branch_id=b_a.branch_idINNER JOINEmployee asE ona.open_emp_id=e.emp_idINNER JOINBranch B_e one.assigned_branch_id=b_e.branch_idWHEREA.product_cd= 'CHK';

Self-Joins

Because the employee has self-quoted superiors, there is a possibility that there is a case in Django example.

SELECT  from  as INNER JOIN  as  on = e_mgr.emp_id;

Non-equi-joins

In the on condition of the join statement, you don't have to use the equals sign or

SELECT ' VS '  from  as INNER JOIN  as  on < WHERE = ' Teller '  and = ' Teller ';

SQL advanced Query Tips (two joins in the same table, self-contained joins, unequal joins)

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.