Level 1
any repy
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi i have this query but for 100 users i want to get the total users in country and the total order amount of the users but i the issue is when i add COUNT(DISTINCT u.id) it gave me 16 users in USA and when i do it without DISTINCT it gave me 85 users in USA but i don't have any duplication in rows so why this happen please ?
SELECT c.*,COUNT (DISTINCT u.id) as total_users, SUM(o.total) as total_orders_amount FROM countries c INNER JOIN users u ON u.countryId=c.id INNER JOIN orders o ON u.id=o.userId GROUP BY c.name;
Please or to participate in this conversation.