title: CakePHP 3 Raw SQL Query
body: <p>I'm using CakePHP 3, I need to run a raw SQL query on multiple tables. In CakePHP 2, this could be done by using the query() method on any model ( <code>$this-&gt;Messages-&gt;query("select..")</code> ).</p>
  
  <p>I need the method that allows me to run a SQL query in CakePHP 3. Following is the code snippet I'm using:</p>
  
  <pre><code>$aumTable = TableRegistry::get('Messages');
  $sql = "SELECT (SELECT COUNT(*) FROM `messages`) AS `Total_Count`,
          (SELECT COUNT(*) FROM `messages_output`) AS `Total_Output_Count`,
          (SELECT COUNT(*) FROM `messages_output` WHERE `is_success`=1) AS `Total_Successful_Output_Count`,
          (SELECT COUNT(*) FROM `messages_output` WHERE `is_success`=0) AS `Total_Error_Output_Count`,
          (SELECT COUNT(*) FROM `users`) AS `Total_User_Count`;";
  
  // to run this raw SQL query what method should i use? query() doesn't work..
  // $result = $aumTable-&gt;query($sql); ??
  // $result = $aumTable-&gt;sql($sql); ??
  </code></pre>
  
  <p>If you can provide links to CakePHP 3 model documentation where I can find this info, that would be helpful too. I tried searching on google but could only find questions related to CakePHP 2.</p>