title: MYSQL query SELECT from one table and join results with other table
body: <p>I have two tables <code>MESSAGES</code> and <code>USERS</code>:</p>
  
  <p><code>MESSAGES</code>:</p>
  
  <pre><code>|id|user_id|message|1st number|2nd number|
  </code></pre>
  
  <p><code>USERS</code>:</p>
  
  <pre><code>|user_id|name|
  </code></pre>
  
  <p>I'm trying to display a message and by user_id get username next to the message. Is it possible to do it in just one query?</p>
  
  <p>At this moment my demo query looks like that but it does not work.</p>
  
  <pre><code>SELECT *
   FROM   messages
   WHERE  1st number BETWEEN $x AND $z
   AND 2nd BETWEEN $x AND $z
   LEFT JOIN users
   ON users.user_id= messages.user_id
   ORDER BY time DESC
  </code></pre>
  
  <p>The error which I get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN users ON WHERE users.user_id= messages.user_id ORDER BY time DESC' at line 5</p>