title: Handling missing columns in MySQL
body: <p>Working on parsing a bunch of databases put together in an older, more freewheeling time into a new schema. Basically it's one database per year, with database names like foo98, foo99, foo2000, etc.</p>
  
  <p>So for the most recent foo data, I can do something like</p>
  
  <pre><code>SELECT foo_person.mdname AS middle_name,
  ...
  FROM foo_person, foo_place, foo_thing
  </code></pre>
  
  <p>As you get back into earlier versions of the foo database, middle name isn't stored. I've tried to build a kind of universal query, something like:</p>
  
  <pre><code>SELECT IFNULL(foo_person.mdname, "") AS middle_name,
  ...
  FROM foo_person, foo_place, foo_thing
  </code></pre>
  
  <p>but MySQL complains about unknown column foo_person.mdname, which is entirely reasonable as it doesn't exist.</p>
  
  <p>Is there some way to handle non-existent columns with just MySQL syntax, or will I have to write database-specific import queries?</p>