How To Name Query Output Columns

Q

How To Name Query Output Columns? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqueries

✍: FYIcenter.com

A

Each column in the query output has a default name. If you don't like the default name, you can specify a new name for any column in the query output by using the AS clause. The following statement shows you a good example:

mysql> SELECT tag AS Category, YEAR(created) AS Year, 
   COUNT(*) AS Counts FROM fyi_links 
   GROUP BY tag, YEAR(created) ORDER BY COUNT(*) DESC;
+----------+------+--------+
| Category | Year | Counts |
+----------+------+--------+
| DBA      | 2006 |      2 |
| DEV      | 2006 |      1 |
| SQA      | 2006 |      1 |
| DBA      | 2005 |      1 |
| DEV      | 2004 |      1 |
| SQA      | 2003 |      1 |
+----------+------+--------+
6 rows in set (0.00 sec)

2007-05-11, 4872👍, 0💬