Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

Count values from one table using two columns in another table

$
0
0

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


Viewing all articles
Browse latest Browse all 717

Trending Articles