Ad

Generate Field In MySQL SELECT

- 1 answer

If I've got a table containing Field1 and Field2 can I generate a new field in the select statement? For example, a normal query would be:

SELECT Field1, Field2 FROM Table 

And I want to also create Field3 and have that returned in the resultset... something along the lines of this would be ideal:

SELECT Field1, Field2, Field3 = 'Value' FROM Table

Is this possible at all?

Ad

Answer

SELECT Field1, Field2, 'Value' Field3 FROM Table

or for clarity

SELECT Field1, Field2, 'Value' AS Field3 FROM Table
Ad
source: stackoverflow.com
Ad