user3112401
user3112401

Reputation: 373

What is the difference between JOIN USING and JOIN ON?

In general, is there any difference in result set or query performance between:

SELECT * FROM tableA JOIN tableB USING (id);

and

SELECT * FROM tableA ta JOIN tableB tb ON (ta.id = tb.id);

If so, what is the difference?

Pros / Cons to using one over the other?

Upvotes: 2

Views: 810

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269463

When you say USING, then the columns are treated differently in the query:

  • Both tables must have the same columns and names for the join keys. (I think this is a good practice anyway, but USING requires it.)
  • The keys used for the join can only be used without a table alias in the rest of the query.
  • If you do SELECT *, then the join keys are only returned once.

Upvotes: 9

Related Questions