0
table a: id, name
query :SELECT * FROM a
result: list value id, name

i want add a age = 18 to all record and do it with query not manipulate result

ex: SELECT a.*, age = 18 FROM a

How to do ?

Thanks

Addition question:

Could use WHERE clause on value that i have just set.

SELECT ex.title , ex.age
  ( SELECT a.title, 18 as age FROM a
    UNION ALL
    SELECT b.title, 19 as age FROM b) as EX
WHERE age = 19

Maybe it will be slowed ? any better solution?

1
  • 1
    If you just want to return 18 in the age field for all values you should use something like "SELECT a.*, 18 as Age FROM a", although might be better to be done outside mysql?
    – ChrisK
    Aug 23, 2011 at 9:18

3 Answers 3

3
SELECT a.*, 18 age FROM a

should work.

0
2

This should do the job

 Select a.*, 18 as age from a
0
0

If you need it in result, you can use the following query

select a.*, 18 as age from a

If you need to update records in your db, you ahve to use Update

update a set age=18
1
  • the a table has not age field
    – Chameron
    Aug 23, 2011 at 9:22

Your Answer

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

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