Handling Ambiguous Attribute Names
tags: #sql
We can prevent ambiguity by qualifying the attribute name with the relation name.
This means specifying the table or relation name along with the attribute name to avoid ambiguity when a column with the same name exists in multiple tables:
table_name.column_name
Consider the following:
- We have two tables
customerandorders, both of which have a column namedid - Need to qualify the attribute name with the relation name when querying both tables to avoid confusion.
SELECT customer.id, customer.name, orders.order_date
FROM customer
INNER JOIN orders ON customer.id = orders.customer_id;