title: Order by query using specific column or alphabetical. - Coldfuison
body: <p>we have a coldfusion website that retrieves our categories then displays them alphabetically.</p>
  
  <p>We would like to be able to force an order by manually arranging the categories with a 'sort' column with a number in but if this number is equal to 0 or null use alphabetical order.</p>
  
  <p>so at the moment the query is </p>
  
  <pre><code>&lt;cfquery name="qGetThrdCat" datasource="#request.dsn#"&gt;
      SELECT *
      FROM tbl_prdtthrdcats, tbl_scnd_thrdcat_rel
      WHERE tbl_scnd_thrdcat_rel.thrdctgry_ID = tbl_prdtthrdcats.thrdctgry_ID
      AND tbl_scnd_thrdcat_rel.scndctgry_ID = #URL.secondary#
      AND thrdctgry_archive = 0
      ORDER BY thrdctgry_Name ASC
  &lt;/cfquery&gt;
  </code></pre>
  
  <p>It works if I try </p>
  
  <pre><code>ORDER BY thrdctgry_Sort ASC
  </code></pre>
  
  <p>but I can't for the life of me join them up, mainly down to my lack of programmer skills.</p>
  
  <p>Any advice would be greatly appreciated.</p>