EXISTS simply tests whether the subquery returned any rows or not.even if the sales_fact_table has a single row, the product table count will count all the rows in the product table.What you need is a join condition or a subquery with a IN() you should change this :select count(*) -- 69501,67141,2360from Product pwhere exists (select material_idfrom sales_fact_table swhere s.material_id = p.material_id)
to something like select count(p.*) -- 69501,67141,2360from Product as p inner join sales_fact_table as s on p.product_id = s. material_id
-ashokhttp://www.unganisha.org