title: IF Statement in MySQL, using THEN and ELSE
body: <p>I am testing out IF statements in MySQL for the first time and I am coming across an error. </p>
  
  <p>I am trying to firstly, find out how many rows are in the table, then depending on whether the count is less than or equal to five, return all of the rows in the table, or if it isn't, return all posts in the range used within the LIMIT clause. </p>
  
  <p>The error I am receiving is as follows;</p>
  
  <blockquote>
    <p>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 'IF SELECT COUNT(*) FROM <code>Posts</code> &lt;= 5 THEN SELECT * FROM <code>Posts</code>
    ELSE SELECT * FR' at line 1</p>
  </blockquote>
  
  <p>Please can you tell me where I am going wrong? </p>
  
  <p>Max.</p>
  
  <pre><code>$query = mysql_query(
      "IF SELECT COUNT(*) FROM `Posts` &lt;= 5 
       THEN 
           SELECT * FROM `Posts` 
       ELSE 
           SELECT * FROM `Posts` LIMIT $from, $limit") 
       or die(mysql_error());
  </code></pre>