title: What is the right syntax of IF statement in MySQL?
body: <p>I have a small and simple MySQL code. But whenever I run it, I get error #1064.  Can you tell me what is my mistake here?</p>
  
  <pre><code>IF ((SELECT COUNT(id) FROM tbl_states) &gt; 0) THEN
      BEGIN
          SELECT * FROM tbl_cities;
      END
  END IF
  </code></pre>
  
  <p>I also used some other conditions like the below one, but again I got an error.</p>
  
  <pre><code>IF (1=1) THEN
      BEGIN
          SELECT * FROM tbl_cities;
      END
  END IF
  </code></pre>
  
  <p>What I actually want to do is something like this:</p>
  
  <pre><code>IF ((SELECT COUNT(id) FROM tbl_states) &gt; 0) THEN
      BEGIN
          UPDATE ...
      END
  ELSE
      BEGIN
          INSERT ...
      END
  END IF
  </code></pre>