MySQL Forums
Forum List  »  Newbie

Re: mysql question
Posted by: Jonathan Stephens
Date: September 19, 2014 12:36AM

There's also an optional "AS" keyword. Perhaps this example that uses it will make things clearer to Phillip:

mysql> SELECT * FROM test;
+----+------+---------------------+
| id | data | ts                  |
+----+------+---------------------+
|  1 | New  | 2014-08-20 18:47:42 |
+----+------+---------------------+
1 row in set (0.00 sec)

mysql> SELECT id, data AS Words, ts AS 'Time Created' FROM test;
+----+-------+---------------------+
| id | Words | Time Created        |
+----+-------+---------------------+
|  1 | New   | 2014-08-20 18:47:42 |
+----+-------+---------------------+
1 row in set (0.00 sec)

The AS keyword is not required (e.g. "SELECT id, data Words, ts 'Time Created' FROM test;" works exactly the same as the version of the statement that uses AS), but I always include it because I think it makes the aliasing stand out better when trying to read long SQL statements.

As the Manual states, NAME_CONST() is for internal use only: It is not intended for, not needed by, and not supported for end users. Its behaviour and semantics are subject to change without prior warning, which is why you should not rely on it in your applications. Generally, the only place you'll ever see it actually used is in the output of mysqlbinlog.

Here's the example for NAME_CONST() from the Manual:

mysql> SELECT NAME_CONST('myname', 14);
+--------+
| myname |
+--------+
|     14 |
+--------+

You can obtain exactly the same result like this:

mysql> SELECT 14 AS myname;
+--------+
| myname |
+--------+
|     14 |
+--------+
1 row in set (0.00 sec)

Use this. Don't use NAME_CONST().

cheers,

Jon Stephens
MySQL Documentation Team @ Oracle

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Written By
Posted
September 18, 2014 05:03AM
September 18, 2014 05:57AM
September 18, 2014 06:09AM
Re: mysql question
September 19, 2014 12:36AM
September 19, 2014 07:02PM
September 30, 2014 05:03AM
September 18, 2014 11:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.