title: Run a query in a MySQL stored procedure if a condition is true
body: <p>I am using MySQL database and trying to create a stored procedure.  How can I make it so that if the result of query1 has no records, then it execute a different query?</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>/* CREATE DB */
  CREATE DATABASE mydata;
  use mydata;
  /* TABLE */
  CREATE TABLE mydata (
  ID BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  Name                        VARCHAR(255) NOT NULL,
  Value                       VARCHAR(255) NOT NULL
  ) ENGINE=InnoDB;
  INSERT INTO mydata (Name, Value) VALUES ("testname", "testvalue");
  
  /* STORED PROCEDURE */
  delimiter //
  CREATE PROCEDURE myproc(IN myTable VARCHAR(255), 
                          IN myValue VARCHAR(255), 
                          IN myValueTwo VARCHAR(255))
  BEGIN
      SET @iTable=myTable;
      SET @iValue=myValue;
      SET @iValueTwo=myValueTwo;
  
      SET @query = CONCAT('SELECT Name FROM ', @iTable, 
          ' WHERE Value="', @iValue, '"');
      SET @querytwo = CONCAT('SELECT Name FROM ', @iTable, 
          ' WHERE Value="', @iValueTwo, '"');
      PREPARE QUERY FROM @query;
      EXECUTE QUERY;
  
  END //
  delimiter ;
  
  /* CALL */
  call myproc("mydata", "testvalue", "");
  </code></pre>
  
  <p>I want to run a query, and execute a secondary query only if the first has no rows.  What is the best way to do this?</p>