|
|
|
Custom Search
| |
|
| |
|
Using Column Alias in SELECT Statement
By default, after executing a SELECT statement, the column heading(s) displayed in the result set is the name of the column in the table. You can override it with a column alias. That is, you can change a column heading by using a column alias. Read Prerequisites for this tutorial and practices if you haven't done so. Consider the following facts when using column alias:
Practice #1: execute SELECT statement with or without using keyword AS before column alias name In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Use the keyword AS. The queries above display CategoryID and CategoryName from categories table. In the first query, we have used optional keyword AS before the column alias name. This is the recommended way to do it. The second query doesn't use optional keyword AS - not recommend. Both queries have produced the same result whether the AS keyword is used or not.
Query result set - 8 rows returned: Practice #2: execute SELECT statement with single or double quotes around column alias name In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Use double quotes around column alias The first query uses double quotation marks to enclose column alias name. This is the recommended way to do it. The second query uses single quotation marks to enclose column alias name - not recommend as single quotes are normally used to enclose character strings. Literal strings are discussed in Using Literal Character Strings section. Note that both queries have produced the same result whether single or double quotes are used.
Query result set - 8 rows returned:
|
|
Copyright © 2012 GeeksEngine.com. All Rights Reserved. This website is hosted by LunarPages. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
| Home | Kung Fu Timer | Feedback | Terms of Use | Privacy Policy |