PostgreSQL Usage Summary

Source: Internet
Author: User

1. Use of using

Using is an abbreviated concept: it receives a comma-delimited list of field names that must be common to the join table and eventually form a join condition that indicates that the field pairs must be the same.

The using (A, B, c) is equivalent to ON (t1.a = t2.a and t1.b = t2.b and t1.c = t2.c) except if on is used, then in the result a, B, and C fields each will have two, and with using, each field is only There will be one.

As an example,

Suppose we have a table T1

num | Name
-----+------
1 | A
2 | B
3 | C
and T2

num | Value
-----+-------
1 | Xxx
3 | yyy
5 | zzz

= = SELECT * from t1 INNER JOIN t2 on t1.num = T2.num;
num | name | num | Value
-----+------+-----+-------
1 | A | 1 | Xxx
3 | C | 3 | yyy
(2 rows)

When using on t1.num = T2.num, there are two num columns in the result, and the contents are the same.

= = SELECT * from t1 INNER JOIN T2 USING (num);
num | name | Value
-----+------+-------
1 | A | Xxx
3 | C | yyy
(2 rows)

When using (num), there is only one column of num in the result.

SELECT * from t1 INNER JOIN T2 USING (num);

Equivalent to

SELECT * from t1 NATURAL INNER JOIN T2;

NATURAL is an abbreviated form of using: It forms a using list consisting of the names of the fields that appear in the two tables. As with using, these fields appear only once in the output table.

Related Article

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.