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 Reporting with SQL Working with Text Practice Session

Can you select all (*) but still use functions or alias certain columns without writing them all out?

I thought of this while in the doing the practice questions in the playground.

In the "Changing Case" part, for example, if I want to return all the columns but still return the 'title' in all uppercases, do I need to write out all the columns even if it's only one that I want to change?

If I write my code like this -

SELECT *, UPPER(title) FROM movies;

then it'll give me an extra column with all uppercase movie titles at the end when all I really want to do is alter one column but still return the rest.

Seems like it'd be tedious to have to write out all the columns in a large datasets when I only want to transform one column but return the rest. Is that the only way?

Thanks!

1 Answer

Steven Parker
Steven Parker
229,644 Points

The asterisk (*) shorthand is only useful when you want to show all columns with their normal column names. You can add additiona comma-separatedl columns to the list but you can't alter or subtract any.

The nature of SQL is that some things will be rather tedious to construct. The good news is SQL engines are good at optimizing, so they will generally perform as well as they might have if you had been able to be more concise..