There are two tables: table customer
consists of information about customers and table payment
consists of information about payments. Primary key customer_id
in the customer
table is a foreign key in the table payment_id
. The following two queries return identical results:
SELECT
payment.customer_id,
last name,
amount
FROM customer
INNER JOIN payment ON customer.customer_id = payment.customer_id
SELECT
customer.customer_id,
last_name,
amount
FROM customer
INNER JOIN payment ON customer.customer_id = payment.customer_id
The only difference between the queries is in the first argument in the SELECT
clause: payment.customer_id
vs customer.customer_id
. As the customer_id
is the column on which the tables are joining on, the distinction between payment.customer_id
and customer.customer_id
seems meaningless. However, if I try to omit the table in the query:
SELECT
customer_id,
last_name,
amount
FROM customer
INNER JOIN payment ON customer.customer_id = payment.customer_id
I receive
[42702] ERROR: column reference "customer_id" is ambiguous
Could you please describe where is ambiguity in the query?