Skip to content
Advertisement

SQL – Generate column from sum of columns from different table

I have two tables: The first one contains numeral values, it looks like this:

The id column is the primary key; it has the attribute AUTO_INCREMENT. All columns have the datatype INT.

Now my question: Can I create a table like the following:

Advertisement

Answer

Are you just looking to create a generated column that contains the sum of the three other columns?

If so, you should add it directly to the original table:

If you don’t want (or can’t) alter the original table, I would suggest creating a view instead:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement