- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
Empowering Insights, Unleashing Possibilities
Data Science/Business Analytics for Small Business Applications › Forums › SQL › Naming convention with SELECT of columns: Avoid duplication for display with alias
Tagged: alias names with SELECT
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
Reference:
Whether you want to use inner or outer in the final query, using outer now will help you debug https://community.spiceworks.com/topic/2458488-what-is-wrong-with-this-query?page=1#entry-10181316