title: How to sort a table generated from a looped Mysql query in ColdFusion?
body: <p>I have an HTML table that is generated from a query of the 'user' table that finds all users on a system.</p>
  
  <p>A second query uses 'select count' to count how many meetings a user has booked by checking how many times their userID appears in the meetings table.</p>
  
  <pre><code>&lt;cfquery datasource="iPad" name="Two"&gt;
   SELECT COUNT(userID) AS meetingsCount from meeting where userID = '#One.userID#'
   &lt;/cfquery&gt;
  </code></pre>
  
  <p>I would like to be able to reorder the table based on the meetingsCount by clicking a link on the page.
  The problem is I'm not sure how to query this information as it doesn't technically exist on the table in MYSQL.</p>
  
  <p>Edit; code using left join and validation.</p>
  
  <pre><code>select user.userID, user.contactName, user.email, count(meeting.userID)
  as meetingsCount 
   from user where user.userID = 30 
  AND user.userID NOT IN ('1', '2', '3', '4', '58', '59', '62',
  '63', '64', '66', '69', '71',    '72', '73', '78', '107')
  AND SUBSTRING( meeting.meetingCode, 5, 2 ) 
  BETWEEN 12 AND 22 
  AND SUBSTRING( meeting.meetingCode, 7, 2 ) 
  BETWEEN 1 AND 12 
  AND SUBSTRING( meeting.meetingCode, 9, 2 ) 
  BETWEEN 01 AND 31
  left outer join meeting on user.userID = meeting.userID
  </code></pre>