SQL lessons – Naming Columns

SQL lessons – Naming Columns cover image
  1. Home
  2. MySQL
  3. SQL lessons – Naming Columns

MySQL allows you to name the displayed columns. So instead of f_name or l_name etc. you can use more descriptive terms. This is achieved with AS.

select avg(salary) AS
'Average Salary' from
employee_data;

+----------------+
| Average Salary |
+----------------+
|     95095.2381 |
+----------------+
1 row in set (0.00 sec)

Such pseudo names make will the display more clear to users. The important thing to remember here is that if you assign pseudo names that contain spaces, enclose the names in quotes. Here is another example:

select (SUM(perks)/SUM(salary) * 100)
AS 'Perk Percentage' from
employee_data;

+-----------------+
| Perk Percentage |
+-----------------+
|           19.53 |
+-----------------+
1 row in set (0.00 sec)
MySQL