w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
SQL query to join two tables, adding new records if records missing

If the IP_Data_Yearly table is empty, an INSERT with a subquery that aggregates count by IP should do the trick:

  SELECT IP_Address, SUM(Count)
  FROM (
    SELECT IP_Address, Count FROM IP_Data_January
    UNION ALL SELECT IP_Address, Count FROM IP_Data_February
  ) IPCombined
  GROUP BY IP_Address

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.