开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜