0

Is there any way I can add an integer to each entry in the result array returned from an SQL query?

For example a query like:

SELECT * FROM mytable

Is there anything I can add to that statement to add a column to the resulting array with a specified integer in it?

3
  • 3
    Something like SELECT *, 1 AS newCol FROM mytable ;). Commented May 30, 2015 at 14:38
  • Thanks, does newCol need to be added as a column in the table? Commented May 30, 2015 at 14:57
  • No you don't need to add a new column to your table that's just an alias ;). Commented May 30, 2015 at 14:59

1 Answer 1

1

Try something like this:

SELECT *, 1 AS newCol 
FROM mytable

You can also set your specific type of your field by using CAST like this:

SELECT *, CAST(1 AS DECIMAL(4,2)) As newCol
FROM mytable
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.