Posts List

How To Get 35 Records FROM 1 — Or Why You Must Declare Your JOIN Type

The FROM clause in MySql is completed first and it provides the table from which other operations will be run. Even with that essential description, some constructions of the FROM can be difficult to understand and provide you with wildly unexpected results. Those unexpected results come from the fact that the tables in the FROM clause are combined into one table for querying whether you specify the type of JOIN or not.

MySql Integer Sequence Generation

Generating integer sequences (e.g. all numbers between 20 and 100) in MySql is much harder than it needs to be. Other DBMS products have had such support for quite awhile. In PostgresSql, you can do something like so: SELECT * FROM generate_series(1, 6) number That will generate a table of numbers from 1 to 6. Seems like basic functionality right? Not in glorious MySql. You have several options but they are either hacky or require a fair amount of work.

Fizz Buzz in MySql Using a Stored Procedure and a Temporary Table

As a fun mental exercise I whipped this up. Is this really useful? Probably not. It is really a “code kata” if nothing else. I wouldn’t recommend using stored procedures in most situations since it is generally considered good practice to keep your logic in your code and not in the database layer. Rules The standard rules for Fizz Buzz are: Write a program that prints the numbers from 1 to 100.