Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I need to do a SELECT query where I get the value of the field "money". The field doesn't actually exist in the database. I just need the query to return this field with a fixed value; in this case a value in USD.

How do I return a constant value in a SELECT statement?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

If the value is always going to be the same you can do something like this:

SELECT 'USD' AS `MONEY`, a.*
  FROM INFORMATION_SCHEMA.SCHEMATA AS a

Just replace a.* with the columns you want to return and INFORMATION_SCHEMA.SCHEMATA with the schema and table(s) you want to query.

I hope this is helpful to you.

share|improve this answer
    
Thanks a lot. Works like a charm. Just curious. What is that last 'AS a' (after 'FROM INFORMATION_SCHEMA.SCHEMATA') for? –  fedejp Aug 8 '12 at 18:03
    
No problem at all. The AS specifies an alias for the table, it is essentially a short name that you can reference the table by. –  Mr.Brownstone Aug 8 '12 at 18:05
    
Oh, great. I didn't that you could use aliases for tables. Thanks a lot! –  fedejp Aug 8 '12 at 18:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.