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.