Editor settings

General settings

Save settings

SQL for beginners

Renaming columns without AS #

In the previous lesson, we changed the result column name with the keyword AS, but we can omit the keyword AS as well. For example:

SELECT
    column_1 AS new_col_1,
    column_2,
    column_3 AS new_col_3
FROM table_name;

can be written as

SELECT
    column_1 new_col_1,
    column_2,
    column_3 new_col_3
FROM table_name;

Exercise #

Write a command that retrieves the data from customers table and rename two columns.

  • Rename column first_name to name.
  • Rename column last_name to lastName.
  • Must not use keyword AS

Expected result

+----------+----------+
|   name   | lastName |
+----------+----------+
|  Megan   |  Chang   |
| Jonathan |  Dixon   |
|  Tammy   |  Howard  |
|   Juan   |  Campos  |
| Vanessa  |  Patel   |
|   Kyle   |  Blair   |
|  Anita   |  Gomez   |
|  Tammy   |  Woods   |
|  Bryan   | Sellers  |
| Jennifer |   Ross   |
+----------+----------+
Solution
SELECT
    first_name name,
    last_name lastName
FROM
    customers;
Output will be displayed here