title: Sorting order behaviour between Postgres and Mysql
body: <p>I have faced some strange sort order behaviour between Postgres &amp; mysql.</p>
  
  <p>For example, i have created simple table with <strong>varchar</strong> column and inserted two records as below in both <strong>Postgres and Mysql</strong>.</p>
  
  <pre><code>create table mytable(name varchar(100));
  insert into mytable values ('aaaa'), ('aa_a');
  </code></pre>
  
  <p>Now, i have executed simple select query with order by column. </p>
  
  <p>Postgres sort order:</p>
  
  <pre><code>test=# select * from mytable order by (name) asc;
   name 
  ------
   aa_a
   aaaa
  (2 rows)
  </code></pre>
  
  <p>Mysql sort order:</p>
  
  <pre><code>mysql&gt; select * from mytable order by name asc;
  +------+
  | name |
  +------+
  | aaaa |
  | aa_a |
  +------+
  2 rows in set (0.00 sec)
  </code></pre>
  
  <p>Postgres and mysql both returning same records with different order. </p>
  
  <p>My question is which one correct? </p>
  
  <p>How to get results in same order in both database?</p>
  
  <h2>Edited:</h2>
  
  <p>I tried with query with ORDER BY COLLATE, it solved my problem.</p>
  
  <p>Tried like this</p>
  
  <pre><code>mysql&gt; select * from t order by name COLLATE utf8_bin;
  +------+
  | name |
  +------+
  | aa_a |
  | aaaa |
  +------+
  3 rows in set (0.00 sec)
  </code></pre>
  
  <p>Thanks.</p>