title: Efficiently sorting data from DB using Java?
body: <h3>What we have:</h3>
  <p>3 MySQL DB tables: user, text, friend</p>
  <p><strong>user</strong>: username, password, email, etc.</p>
  <p><strong>text</strong>: username, text, date, etc.</p>
  <p><strong>friend</strong>: username, friend_username, etc.</p>
  <h3>Task:</h3>
  <p>Write an algorithm (in Java) to <strong>show 10 latest texts from your friends</strong>.</p>
  <p>Ultimate target is to have running time within <em>O(n log n)</em>.</p>
  <p>DB tables can be modified (added new ones) as required.</p>
  <p><em>Data volume:</em> 200 000 users, ~50 text per user.</p>
  <p>I would appreciate any ideas, examples, points, etc. Thank you!</p>
  <p><em>(Not a homework. Pure problem, looking for performance improvement)</em></p>