title: SQL query to select group then order from 2 tables
body: <p>Here are the tables</p>
  <p>TAGS :</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>tag_id</th>
  <th>tag_name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>SENT</td>
  </tr>
  <tr>
  <td>2</td>
  <td>AIRTIME</td>
  </tr>
  <tr>
  <td>3</td>
  <td>RECEIVED</td>
  </tr>
  <tr>
  <td>4</td>
  <td>KOPOKOPO</td>
  </tr>
  <tr>
  <td>5</td>
  <td>RESTAURANT</td>
  </tr>
  <tr>
  <td>6</td>
  <td>PAID</td>
  </tr>
  <tr>
  <td>7</td>
  <td>UBER</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>TRANS_TAG</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>tag_id</th>
  <th>trans_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>1</td>
  </tr>
  <tr>
  <td>4</td>
  <td>1</td>
  </tr>
  <tr>
  <td>5</td>
  <td>1</td>
  </tr>
  <tr>
  <td>6</td>
  <td>1</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>2</td>
  </tr>
  <tr>
  <td>5</td>
  <td>2</td>
  </tr>
  <tr>
  <td>6</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The following are default tags (SENT, AIRTIME, RECEIVED, PAID), the rest are not default tags.
  The TRANS_TAG table tracks a transaction id and the tags attached to it.</p>
  <p>I would like to write a select SQL statement that selects from these two tables and achieves the following result. - it returns a list of all the tags that have been attached to at least one transaction. it then orders them alphabetically but grouped with the default tags first.</p>
  <p>This is the desired result</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>tag_name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>AIRTIME</td>
  </tr>
  <tr>
  <td>PAID</td>
  </tr>
  <tr>
  <td>RECIVED</td>
  </tr>
  <tr>
  <td>SENT</td>
  </tr>
  <tr>
  <td>KOPOKOPO</td>
  </tr>
  <tr>
  <td>RESTAURANT</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>This is the code that I have so far</p>
  <pre class="lang-sql prettyprint-override"><code>String SQL = &quot;SELECT &quot;
                  + KEY_TAG_TITLE +
              &quot; FROM &quot; + TABLE_TRANS_TAG
            + &quot; INNER JOIN &quot; + TABLE_TAG + &quot; &quot; + &quot;ON &quot; + TABLE_TRANS_TAG + &quot;.&quot; + KEY_TRANS_TAG_TAG_ID
                  + &quot; = &quot; + TABLE_TAG + &quot;.&quot; + KEY_TAG_ID
            + &quot; GROUP BY &quot; + KEY_TAG_TITLE
            + &quot; ORDER BY &quot; + TABLE_TAG + &quot;.&quot; + KEY_TAG_TITLE + &quot; ASC, &quot; + TABLE_TAG + &quot;.&quot; + KEY_ROW_ID + &quot; ASC&quot;;
  </code></pre>