adding string to a select statement to include in result set
I'm trying to add a string to a mysql result set to save manipulating the results with php later.
This is what I want to do but it gives me an error.
SELECT 'new' AS condition
UNION
SELECT p.Name AS title, p.meta_desc AS description, p.product_Id AS id from products AS p
开发者_如何转开发I can do this:
SELECT p.Name AS title, p.meta_desc AS description, p.product_Id AS id, 'new' from products AS p
but it gives new => new , ideally I would like the result column to be called 'descripiton' and retrieve 'condition' => 'new'
SELECT p.Name AS title,
p.meta_desc AS description,
p.product_Id AS id,
'new' AS `condition`
FROM products AS p
You can alias the literal. Condition is a reserved word, so you have to use backticks.
精彩评论