Skip to content
Advertisement

MySQL column to show the sum of column in another table

I have two tables in SQL both hold the ID of users.

Table Accounts

Table Transactions

The table accounts column points should have the sum of that ID in table transactions. So in table one, the output should be points of ID 1 to be 5 and id 2 to be 20.

I am new to MySQL so if you could just explain the query a bit will be appreatiated.

Advertisement

Answer

You need an UPDATE statement:

The correlated subquery returns the sum of points of each ID.

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