Playing with Movies Table: Change column name and showing ALL (*) FROM Movies

Hello everyone, I’m just getting started on SQL. This is the link to the “exercise”: https://www.codecademy.com/paths/data-analyst/tracks/dsf-learn-sql/modules/learn-sql-queries-3bde9474-c463-41fa-9633-d2dfaf5df29c/lessons/queries/exercises/queries-review
I was playing with the table Movies and can’t figure out how to change the name of a column WHILE showing all of the columns ie. I want to rename imdb_ratings to ‘Puntajes’ (in Spanish). I know I need to type SELECT imdb_ratings AS ‘Puntajes’, however that only queries that specific column. I want to see all of the table with that column renamed. How can I go about this?

¡Hola!

There are two ways in which you can achieve this in SQL, the first one might require a bit of labor as it involves typing out all the columns and adding an ALIAS to those that you want the rename:

SELECT imdb_ratings AS Puntajes, column2, column3 FROM [table]  

The second way is explicitly naming the column you wish to rename, and then using * to get all the other columns:

SELECT imdb_ratings AS Puntajes, * from [table]

The second way does have a side effect of having the specified column appear twice.

Hope this helps!

1 Like