Skip to content
Advertisement

How to update table from another table, with 2 columns

I am using SQL Server database and want a way to update MachinesSummary.ShareCount.

Here are my two tables

MachinesSummary

The other table is MachineDetails

I want to update ShareCount in the MachineSummary table with the count of processes that both Machine1 and Machine2 share.

For record 1 in the MachineSummary table, I want the number of processes both share in MachineDetails which is 1 in this case

While for record 4 the ShareCount is 2

I tried this

But I wonder if there is an easier high performance way

The MachineDetails table has 250 million rows.

Advertisement

Answer

Well, I would use a self-join to get the number of combinations:

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