1

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'

5
  • You already have a column called description in your 2nd query. You can't have two columns with the same name. Do you want the string once per row or once per select? Commented Aug 25, 2011 at 7:05
  • sorry, I meant 'condition' as in the first query. Commented Aug 25, 2011 at 7:09
  • Ah, I see it is the name 'condition' that I can't use for some reason. Changing 'new' AS conditions in the second statement worked. Is there anyway I can use condition as a column? Commented Aug 25, 2011 at 7:13
  • Answering my own question: If I put it in quotes - 'new' AS 'condition' works Commented Aug 25, 2011 at 7:15
  • Updated my answer, use backticks Commented Aug 25, 2011 at 7:15

1 Answer 1

3
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.