将字符串添加到选择语句以包含在结果集中 [英] adding string to a select statement to include in result set
本文介绍了将字符串添加到选择语句以包含在结果集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向 mysql 结果集中添加一个字符串,以节省以后使用 php 操作结果的时间.
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
我可以这样做:
SELECT p.Name AS title, p.meta_desc AS description, p.product_Id AS id, 'new' from products AS p
但它给出了 new => new ,理想情况下我希望结果列被称为 'descripiton' 并检索 'condition' => 'new'
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
您可以为文字别名.Condition 是保留字,所以你必须使用反引号.
You can alias the literal. Condition is a reserved word, so you have to use backticks.
这篇关于将字符串添加到选择语句以包含在结果集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文