title: Mysql select a field conditionally
body: <p>i've 10 databases and each one contains a users table with the following structure :
  ID,Name,Email,Address</p>
  
  <p>but for some reason the fields Email AND/OR Address are missing in some users table</p>
  
  <p>I'm trying to merge all this data using this query (by changing only the DB name in the query) : </p>
  
  <pre><code>SELECT ID, CASE
           WHEN EXISTS(
              SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'users' AND COLUMN_NAME = 'Email' AND TABLE_SCHEMA='DB1'
           )
             THEN  Email 
           ELSE ''
         END from `users`
  , CASE
           WHEN EXISTS(
              SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'users' AND COLUMN_NAME = 'Address' AND TABLE_SCHEMA='DB1'
           )
             THEN  Address 
           ELSE ''
         END from `users`
  </code></pre>
  
  <p>but for some tables i'm getting this error </p>
  
  <blockquote>
    <p>Unknown column 'Email' in 'field list'</p>
  </blockquote>
  
  <p>OR </p>
  
  <blockquote>
    <p>Unknown column 'Address' in 'field list'</p>
  </blockquote>
  
  <p>Any idea on how to solve this problem ?</p>
  
  <p>Thanks</p>