title: How to use mysql select rows from multiple categories and display a list with data for each category?
body: <p>Let's say i have a database design like this:</p>
  
  <p>for the data:</p>
  
  <pre><code>id |    title     | category
  1  | first title  | 1
  2  | second title | 4
  3  | third title  | 5
  4  | fourth title | 2
  5  | fifth title  | 3
  6  | other title  | 1
  </code></pre>
  
  <p>and for the categories:</p>
  
  <pre><code>id | name 
  1  | music 
  2  | movies
  3  | funny 
  4  | people 
  5  | sport 
  </code></pre>
  
  <p>How can i output a list with each category with item title from that category?</p>
  
  <p>somethink like:</p>
  
  <pre><code>&lt;div&gt;
  &lt;h1&gt;music&lt;/h1&gt;
  &lt;div&gt;first title&lt;/div&gt;
  &lt;div&gt;other title&lt;/div&gt;
  &lt;div&gt;
  
  &lt;div&gt;
  &lt;h1&gt;movies&lt;/h1&gt;
  &lt;div&gt;fourth title&lt;/div&gt;
  &lt;div&gt;
  
  // and so on...
  </code></pre>
  
  <p>I don't know how to formulate the mysql query for a result like this...</p>
  
  <p>Can somebody please advise me? (i hope the example can be understood easily) </p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT:
  i used Eugen Rieck's code but i don't know how to do the following thing</strong></p>
  
  <p>how can i order by the <code>categories.id</code> and <code>titles.id</code> in the same time eventually use a where condition after that? </p>
  
  <p>something like this:  <code>ORDER BY titles.id DESC LIMIT 0, 10 WHERE titles.views &gt; 10</code></p>