title: SQL IF ELSE WITH MULTIPLE SELECT STATEMENT
body: <p>I want to optimize these SQL queries using if-else but how I should use it? .
  if this query result contain 'ALL'</p>
  <pre><code>SELECT
  bdsubcategory.subcategoryID as ID,
  bdsubcategory.subcategoryName as Name
  FROM
  phonebook.newsms_subscription
  INNER JOIN bdsubcategory ON bdsubcategory.subcategoryID = newsms_subscription.subcategoryID
  INNER JOIN newsms_client ON newsms_subscription.clientID =newsms_client.clientID
  INNER JOIN newsms_person ON newsms_subscription.personID = newsms_person.personID
  WHERE
  newsms_subscription.isActive = 1 AND
  newsms_person.personID = '856'
  </code></pre>
  <p>Then i want to query this</p>
  <pre><code>SELECT
  bdsubcategory.subcategoryID as ID,
  bdsubcategory.subcategoryName as Name
  FROM
  phonebook.newsms_subscription
  INNER JOIN bdsubcategory ON bdsubcategory.subcategoryID = newsms_subscription.subcategoryID
  INNER JOIN newsms_person ON newsms_subscription.personID = newsms_person.personID
  WHERE
  newsms_subscription.isActive = 1
  GROUP BY subcategoryName
  ORDER BY subcategoryName
  </code></pre>
  <p>otherwise take query1 result .</p>