WebDevelopersNotes logo

home-icon Home / MySQL / SQL lessons – Naming Columns

SQL lessons – Naming Columns

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)

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Caps Lock jokes and funny images

Sponsored Links

Tips

How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]

Fact

The first commercial spam was posted on Usenet by Laurence Canter and Martha Siegel. They used a Perl script to post their message, "Green Card Lottery - Final One?", to about 5,500 discussion groups. [more...]