When selecting columns from multiple tables do I need to state which table the column is from?

I’ve noticed that when I join tables I can get away without adding the table name to the selected columns and still get the results I’m looking for. The answers provided by Codecademy always include the table name, though. Here’s an example from the practice “Learners Mockup Data” question 4.

Learners Mockup Data

The answer I used
SELECT email_domain,
learn_cpp,
learn_sql,
learn_html,
learn_javascript,
learn_java
FROM users
JOIN progress
ON users.user_id = progress.user_id
ORDER BY email_domain;

The Codecademy answer
SELECT users.email_domain,
progress.learn_cpp,
progress.learn_sql,
progress.learn_html,
progress.learn_javascript,
progress.learn_java
FROM users
JOIN progress
ON users.user_id = progress.user_id;

What is the purpose for adding the table name? Is it just so that the coding is easier to follow?

readability might be slightly better.

But if joined tables have the same column names, and you don’t include the table name, SQL would give an ambiguous error. Being unable to tell which column you want.

2 Likes