typestar

USING and column names in SQL

When both sides name the column the same thing, USING says so once.

SELECT
    order_id,
    sku,
    quantity,
    price
FROM order_items
JOIN products
    USING (sku)
ORDER BY order_id, sku;

How it works

  1. USING (col) is ON left.col = right.col with less repetition.
  2. The joined column appears once in the output, not twice.
  3. It only works when the names match, which is a reason to name them well.

Keywords and builtins used here

The run, in numbers

Lines
9
Characters to type
104
Tokens
22
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 16 seconds.

Type this snippet

Step 3 of 9 in Joins, step 11 of 22 in Joins & aggregation.

← Previous Next →