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

Development Tools Database Foundations SQL Calculating, Aggregating and Other Functions String Functions

How to select star (*) but add a string function to one of the columns?

for example let's say I have a table with a lot of columns, and I want to select * but apply upper() to one of the columns without the necessity of add all the columns in the select something like this

select * from users upper(last_name);

I know I can't do it like above, but maybe you have the correct syntax, is this possible?

1 Answer

Daniel Nora
Daniel Nora
2,550 Points

If you want one single column to be returned in uppercase along with the other columns in their default casing, then I surmise you need to be explicit regarding the returned columns.

For instance, your code would be somewhat like:

SELECT UPPER(last_name), first_name FROM users;

This would return the last_name and first_name columns, the former in uppercase and the latter in whatever casing it was saved to the DB.

This doesn't scale very well if you start having too many columns in your database, because you would have to write every single column in the SELECT statement, in which case it would probably be better to let your server-side language convert the desired columns to your desired casing.