sql server - Getting way more results than expected in SQL left join query -


my code such:

select count(*) earned_dollars left join product_reference b on a.product_code = b.product_code a.activity_year = '2015' 

i'm trying match 2 tables based on product codes. expect same number of results total records in table (with year of 2015). reason i'm getting close 3 million.

table has 40,000,000 records , table b has 2000. when run statement without join 2,500,000 results, expect left join, somehow i'm getting 300,000,000. ideas? refered diagram in this post.

it means either left join using part of foreign key, causes row multiplication, or there duplicate rows in joined table.

use count(distinct a.product_code)


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -