title: How to execute my SQL query in CodeIgniter
body: <p>I have a problem with my query and <strong>I need to join two tables from different databases</strong> now my problem is how can I execute my query. I got my syntax format from here </p>
  
  <p><strong>Please visit first this link so you could understand why my SQL syntax is like this</strong><br> <a href="http://www.x-developer.com/php-scripts/sql-connecting-multiple-databases-in-a-single-query" rel="noreferrer">http://www.x-developer.com/php-scripts/sql-connecting-multiple-databases-in-a-single-query</a> <hr>
  Im using CodeIgniter and here is an Idea of what my query looks like:<br> <strong>Notice the way I'm selecting my columns:  DATABASE_NAME.TABLE_NAME.COLUMN_NAME</strong></p>
  
  <pre><code>$ENROLLEES = $this-&gt;load-&gt;database('ENROLLEES', TRUE);
  $ACCOUNTS  = $this-&gt;load-&gt;database('ACCOUNTS', TRUE);
  
  $SELECT    = "SELECT $ACCOUNTS.BALANCES_TABLE.IDNO, $ACCOUNTS.BALANCES_TABLE.balance";
  $FROM      = "FROM $ACCOUNTS.BALANCES_TABLE";
  $WHERE     = "$ACCOUNTS.BALANCES_TABLE.IDNO IN (SELECT $ENROLLEES.ENROLLEES_TABLE.IDNO FROM $ENROLLEES.ENROLLEES_TABLE)";
  
  $SQL       = $SELECT ." ". $FROM ." ". $WHERE;
  </code></pre>
  
  <p><strong>MAIN PROBLEM: How to Execute my query?</strong><br>
  If we do like this in codeIgniter:</p>
  
  <pre><code>$ENROLLEES-&gt;query($SQL); or $ACCOUNTS-&gt;query($SQL);
  </code></pre>
  
  <p>How can I execute my query that Im having multiple databases? What will I provide here<br><code>[database]-&gt;query($SQL);</code> ?</p>