Empowering CS learners, aspiring programmers, and startups with AI, Data Science & Programming insights — scaling skills from learning foundations to enterprise-grade solutions.
Naming convention with SELECT of columns: Avoid duplication for display with alias
›Forums›SQL›Naming convention with SELECT of columns: Avoid duplication for display with alias
SELECT region.name, sales_reps.name, accounts.name
FROM region
JOIN sales_reps
ON region.id = sales_reps.region_id
JOIN accounts
ON accounts.sales_rep_id = sales_reps.id
ORDER BY accounts.name
Why am I getting only one column ‘name’ as output while I expected three.
Reply
SELECT region.name AS RegionName, sales_reps.name AS salesman, accounts.name AS CompanyName
FROM region
JOIN sales_reps
ON region.id = sales_reps.region_id
JOIN accounts
ON accounts.sales_rep_id = sales_reps.id
ORDER BY accounts.name