I have a problem. I have table_1 (col1, col2, value)
and table_2 (col1, col2)
.
I want to count values from table_1
but only the rows which exist in table_2
. In both tables col1
and col2
are key (not primary).
I’ve tried:
select col1, col2, sum(value)
from table_1
where table_1.col2 in (select col2 from table_2)
group by col1, col2 ;
It works , but wrong, select too many rows from table_1