将字符串添加到select语句以包含在结果集中

时间:2011-08-25 06:59:45

标签: mysql

我正在尝试将一个字符串添加到mysql结果集中,以便稍后使用php来保存操作结果。

这是我想要做的,但它给了我一个错误。

SELECT 'new' AS condition
    UNION
SELECT p.Name AS title, p.meta_desc AS description, p.product_Id AS id from products AS p

我可以这样做:

SELECT p.Name AS title, p.meta_desc AS description, p.product_Id AS id, 'new' from products AS p

但是它给出了新的>新的,理想情况下我希望结果列被称为'descripiton'并检索'condition'=> '新'

1 个答案:

答案 0 :(得分:3)

SELECT p.Name AS title, 
       p.meta_desc AS description, 
       p.product_Id AS id, 
       'new' AS `condition`
FROM products AS p

您可以为文字添加别名。 Condition是保留字,因此您必须使用反引号。