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
176,584 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..