Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Querying Relational Databases Joining Table Data with SQL Outer Joins

Aliasing SQL Queries

Would you generally alias a SQL query before you confirmed it as valid for your needs or is it really personal preference and dependent on how unfriendly your column names are?
I recall doing them after confirming the script ran the way I wanted and held the correct data points but before handing it off to whoever requested it.

Is this one of those personal preference things, speaking strictly in terms of "when" you do it, not whether other not its a viable practice.

I guess maybe for larger queries that might be more timely you'd want to only run it once?

1 Answer

Steven Parker
Steven Parker
229,644 Points

I think it depends a lot on who the target audience is.

Assuming you mean aliasing query columns, I would consider who will be reading the output. If it's just me or other developers, I would not alias anything unless it was created by concatenation or a function call and needed a name just to be clear about what it was.

But if the audience will be people with little knowledge of the internal database structure, I would alias any potentially cryptic column name to to something that would have meaning to the person(s) reading the output.

And yes, aliasing would be the last step after confirming the query performs correctly otherwise.

Thx for the sanity check!