Skip to content
PHP2Shell: The PHP Bug
Akshay Thakare

Interview preparation

Answers that explain the decision, the reason, the evidence and the limit — not one-liners.

Choose a question

Swipe to browse

Interview answer

01 / 26

Why can a JOIN silently inflate your totals?

Joining two child tables of the same parent multiplies rows.

One order line joined to two payment rows becomes two rows, so revenue doubles.

State the grain of every table and aggregate to a shared grain before joining.

Visual walkthrough

join fan-out
order_lines — one row per line
O101line 1₹300
payments — one row per attempt
O101P101FAILED
O101P102SUCCESS
lines JOIN payments ON order_id
line 1P101₹300
line 1P102₹300
SUM(line_revenue)₹0

Wrong: the single ₹300 line is counted once per payment attempt.

Fix: aggregate payments to one row per order first

line 1 · paid ✓ · ₹300 → SUM = ₹300

One order line, two payment attempts: a direct join doubles the revenue. Aggregating payments to order grain first keeps one row per line.