Is it possible in mysql to create a table with a column that combines two column values? something like this:
create table test1 (
number1 int,
number2 int,
total int DEFAULT (number1+number2)
);
or like this :
CREATE TABLE `Result` (
`aCount` INT DEFAULT 0,
`bCount` INT DEFAULT 0,
`cCount` = `aCount` + `bCount`
);
I had this issue as well. From Edgar Velasquez' answer here, and the answer to this question, I stumbled upon this incantation:
This works for me on MySQL 5.6.22.
It is not possible to do that exactly, but you can create a view based on a query that combines them:
I would avoid actually storing the combined data in a table, unless you're going to be running lots of queries that will reference the combined data in their WHERE clauses.
You can create a trigger on the table so MySQL calculates and automatically inserts that column value every time an INSERT happens on your test1 table. Make the table:
Then create a Trigger
MySQL documentation on triggers: http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html
Make sure to add the ON UPDATE trigger as well if you expect UPDATES to happen to the rows.
Little fix :