title: Sort MySQL query ASC or DESC depending on value of other table
body: <p>I got a query and I want wort sort the result depending on another database.</p>
  
  <p>This is my query:</p>
  
  <pre><code>SELECT    a.`name`
  FROM      `article` AS a
  LEFT JOIN `container` AS b
         ON b.`id` = a.`container`
  WHERE     a.`container` = '1'
  ORDER BY  b.`sort` ASC;
  </code></pre>
  
  <p>This works fine, but it always sorts the result ascending. Bute I want ist to be sorted depending on the value in the container table.</p>
  
  <pre><code>Article table
  
  id | container | name    | gender
  ---|---------------------|---------
  1  | 1         | Michael | male
  2  | 1         | Joe     | male
  3  | 2         | Karen   | female
  4  | 2         | Andrew  | male
  5  | 3         | Jessica | female
  
  
  Container table
  
  id | sort   | order
  ---|--------|----
   1 | name   | asc
   2 | name   | desc
   3 | gender | asc
   4 | name   | asc
   5 | gender | desc
  </code></pre>
  
  <p>How can I change my query to get the order from the container table?</p>
  
  <p>I would expect this result:</p>
  
  <pre><code>id | container | name    | gender
  ---|---------------------|---------
  2  | 1         | Joe     | male
  1  | 1         | Michael | male
  </code></pre>