Synopsis: Implicit Columns
Let’s get introduced to another antipattern that focuses on listing columns while retrieving data from a database.
We'll cover the following...
A PHP programmer once asked me for help troubleshooting the confusing result of a seemingly straightforward SQL query against their library database:
SELECT * FROM Books b JOIN Authors a ON (b.author_id = a.author_id);
This query returned all book titles as NULL. Even stranger, when the PHP programmer ran a different query without joining the Authors
, the result included the real book titles.
SELECT * FROM Books;
I helped the programmer find the cause of their trouble: the PHP database extension they were using returned each row resulting from the SQL query as an associative array. For example, the programmer could access the Books.isbn
column as $row["isbn"]
using this extension. In their tables, both Books
and Authors
had a column called ...