Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why Your JOIN Doubled Your Totals — There's No Error, Just the Wrong Number

SQL doesn't warn you when a JOIN multiplies your rows — it just quietly hands back more of them than you expected, and every SUM() and COUNT() downstream inherits the mistake. Here's the exact mechanism, and how to catch it before it ships. Adapted from the SQL Essentials Companion Guide . You write a query to total up each customer's orders, and it runs fine — no error, no red text, just a…

When you execute a SQL query that joins multiple tables and aggregates the results with SUM() or COUNT(), it's easy to overlook the fact that the JOIN operation can multiply the number of rows unexpectedly. This multiplication, known as a "fan-out," often leads to inflated totals that look correct but are actually incorrect. The issue arises because each row from one table is matched against multiple rows from another table based on the join condition, resulting in duplicated rows.

This duplication is accurate according to SQL rules, but it can skew the final sum or count. To avoid this error, first check the row count before relying on the total result. If the row count is off, investigate which table is causing the fan-out by joining. Identify the one-to-many relationship in your joins, as that's often the source of the problem.

Refactor your query to aggregate the one-to-many table's data separately in a subquery before joining it back, ensuring the raw data is reduced to one row per key before it's aggregated. Avoid using DISTINCT in place of this approach, as it can discard legitimate duplicate values. Remember, the issue lies in the number of rows produced by the join, not in the aggregate function itself.

By verifying row counts and restructuring your joins to aggregate early, you can prevent silently incorrect totals caused by unexpected fan-out in your SQL queries.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Why GA4 DebugView is not showing events and how to fix it

Google Analytics™ 4 DebugView is the built-in tool to inspect events as they arrive. When events do not show up, the issue can be in the browser, in the network, or in the GA4 settings.

  • Inspect browser using DevTools to identify network issues
  • Verify measurement ID aligns with intended GA4 web data stream
  • Enable debug mode or set debugmode: true in configuration

Gas Optimization Audit: Venus Core Pool

Gas Optimization Audit: Venus Core Pool Target Protocol : Venus Core Pool (TVL: $1351.3M) Gas‑Optimization Audit Report Protocol: Venus Core Pool (Ethereum & L2) TVL: ≈ $1.351 B (as of 26 Sep 2026)…

  • Venus Core Pool has six gas inefficiencies inflating transaction costs.
  • Key inefficiencies include redundant storage reads/writes and unbounded loops.
  • Implementing optimizations could save $2-4 million annually on fees.

Your Exam Form Needs a 20 KB Photo. Now What?

Your exam form is almost done. You have your documents. You have your photo. Then you see: Upload photo: 20–50 KB, 200 × 230 px And suddenly, a simple application becomes a trip to the cyber cafe.

  • FormSaathi offers 9 tools for exam form requirements
  • Photo Resizer ensures photo size between 20-50 KB
  • Platform prioritizes privacy with offline functionality

More from Saturday 26 September →