title: IF EXISTS and multiple SELECT statements
body: <p>I'm relatively new to SQL.</p>
  <p>I'm trying to get a SELECT statement to run only if another SELECT statement returns some results.</p>
  <p>I wrote something like this:</p>
  <pre><code>DO
  $$
  BEGIN
  IF EXISTS
  (SELECT column1, column2 FROM table1 WHERE condition)
  THEN
  (SELECT column2, column3 FROM table2 WHERE condition);
  END IF;
  END
  $$
  </code></pre>
  <p>I'm guessing that the issue here is that &quot;IF EXISTS ... THEN&quot; has to be followed by a a table modifier action, and not by a SELECT statement. Is that correct?</p>
  <p>The purpose, as I'm dealing with a fairly large dataset, is to run the second statement only if the first one returns anything.</p>
  <p>Would WHERE EXISTS be a better option?</p>