If I have two tables as listed below, The first which shows the Raw Data and the second which holds the Compressed Version of the Raw Data:
raw_table:
val
1
1
2
2
2
3
3
4
comp_table:
val count
1 2
2 3
3 2
4 1
I want to compress the raw_data into another table
INSERT INTO comp_table VALUES (
SELECT val, COUNT(val) FROM raw_table
WHERE val NOT IN(
SELECT val FROM comp_data
) GROUP BY val
)
First Questions: Is the above syntax correct?
Second Question: The count is updated, What would be the most efficient query to do the update?
Notes: The data size exceeds a Million Records in the raw_table
Thanks in advance :D