Data Tables

Business applications rarely keep their data in one giant table. Customers, orders, order lines, and products each describe a different thing at a different grain, so each gets its own table, linked to the others by primary and foreign keys. That design, which Microsoft’s Northwind sample database illustrates, avoids repeated and inconsistent copies, and it gives a report its shape: joins build the view a question needs. Reading a table well starts with three questions: what does one row represent, which columns identify it, and what type is each column? Add a fourth: which values are missing? A null means unknown, not zero, and SQL and pandas each have their own rules for how nulls behave in filters, counts, and sums.

With that foundation, the same table operations appear in both SQL and pandas: choosing columns, filtering rows, sorting, grouping and aggregating, and window calculations that compute across related rows while keeping every row visible. Joins get the most attention, because choosing the wrong join type, duplicated or incomplete keys, or a filter placed after a left join can silently drop rows or inflate totals. The habit to build is to predict the row count before running the query and to check it afterwards. The session closes with why SQL looks the way it does: a declarative language, descended from Codd’s 1970 relational model, where you describe the result you want and the database decides how to produce it.

Figure: A Victorian-style illustration of a database

Listen

Relational Architecture in SQL and Pandas

Presentation

Read

Hands-on

Notebooks in 07-Data-Tables

Homework