How to add field values in mysql

Hi Im looking for a simple way to to create a field with values derived from other fields.
Eg I have a field called A and one called B I want to create a field called C which is equal to A*B.
How can I do this in mysql. Thanks in advance.
LeighJorAsked:
Who is Participating?
 
Kim RyanConnect With a Mentor IT ConsultantCommented:
You could try an update statment

update table_name set c = a*b;

If c does not exist, you would need to use the alter table statement frist to create it.
0
 
LeighJorAuthor Commented:
I put in
UPDATE item Set C =`CostPerUnit`*`MultiplierPack`
where Item is tablename.

Get error : Unknown column 'C' in 'field list'  ..so I suppse here is where I use alter. what is syntax of alter statement.
PS
I need to use Mysql and basically like the little I know. But in Acces to do same you only had to SELECT...AS EXPRESSION. Isnt there anything like that in Mysql.
Cheers and Thanks
0
 
Kim RyanConnect With a Mentor IT ConsultantCommented:
try this
alter table item add column C integer;
integer is the data type but you may want to use decimal or float
0
 
LeighJorAuthor Commented:
Excellent. Thank you. Easy Peasy. Cheers Mate
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.