Query results half right after joining two tables


The following query resulted in correct results only for the inner query (post_engagement, website purchases) while all other numbers were incorrectly increased manyfold. Any ideas? Thanks.



Schema of the two tables:



Favorite_ads (id, campaign_id, campaign_name, objective, impressions, spend)



Actions (id, ads_id, action_type, value)



Without knowing the actual table structure, constraints, dependencies and data, it's hard to tell, what the issue may be.



You already have some leads in the comments, which you should consider first.



For example you wrote, that this sub-query returns correct results:



Is this one also giving correct results:



If so, then try replacing your sub-query with that one.



If you still have a problem, then I'd investigate if your join condition is correct, as it would seem, that for a campaign (campaign_id) you could probably have multiple entries with the same id, which will multiply the sub-query results - that depends on what is actually the primary key (or unique constraint) in the favorite_ads.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

The Dalles, Oregon

“Thánh nhọ” Lee Kwang Soo chúc thi tốt, sĩ tử Việt Nam... có dám nhận hay không?

眉山市