MySQL 2 min read
Keep unmatched rows when filtering a LEFT JOIN
A report should show every customer, including customers without paid invoices. Placing invoices.status = 'paid' in the WHERE clause removes the unmatched rows, because their joine...
A place for code I want to explain, mistakes worth remembering, and the occasional story from my life.
MySQL 2 min read
A report should show every customer, including customers without paid invoices. Placing invoices.status = 'paid' in the WHERE clause removes the unmatched rows, because their joine...
MySQL 2 min read
A report uses COUNT(paid_at) as its invoice count. The number is lower than the list because the aggregate excludes NULL values in that column. COUNT(*) counts rows; COUNT(column)...
MySQL 2 min read
A query searches for invoices without a paid timestamp using paid_at = NULL. It returns no rows even though unpaid invoices exist. NULL represents an unknown or absent value, and o...
PHP 2 min read
An API's settings field is a map when values exist, but becomes an array when empty. Some clients tolerate this; strongly typed clients often do not. In PHP, an empty array encodes...
PHP 2 min read
An external platform sends a numeric identifier larger than PHP's integer range. Decoding it as a float can lose precision, and converting that float back to text does not recover...
PHP 2 min read
A small export file is empty by design, but a loose check reports that writing it failed. file_put_contents returns the number of bytes written or false on failure. Writing an empt...
PHP 2 min read
A search endpoint accepts a term and a sort column. Both are strings from the request, but they occupy different positions in SQL. A bound parameter represents a value; it does not...
PHP 2 min read
A customer name beginning with = is ordinary text in your database but may be interpreted as a formula when opened in spreadsheet software. CSV quoting protects field boundaries; i...
PHP 2 min read
A product list sorts by stock level. Many products share the same stock, so a stable secondary key makes the order predictable across pages and repeated runs. The spaceship operato...