title: How to build a select in mysql when a "where" column may not be there
body: <p>Working in ColdFusion, I have a MySql query which could apply to any number of tables.  The particular table is stored in a variable called &quot;basetab&quot;.   So the query begins as</p>
  <pre><code>select * from #basetab#
  </code></pre>
  <p>I go on to check a particular column:</p>
  <pre><code>select * from #basetab# 
  &lt;cfif basetab Eq 'RepSave'&gt;
      where RepSavArch != 'Y'
  &lt;/cfif&gt;
  </code></pre>
  <p>However, I really need to check a column in any table that is named SomethingArch.  Because I know the basetab, I know what the something is.  So I want to write</p>
  <pre><code>    select * from #basetab#
      where #prefix#Arch != 'Y'
  </code></pre>
  <p>This works.  However, not all the tables have a 'somethingArch' column, so I need not to do this unless 'somethingArch' is there.</p>
  <p>Can someone suggest a way to get this done.  I suspect I need a subquery, but don't know how to construct it.</p>