title: SQL: call second query if no rows are returned from the first query
body: <p>I'm struggling to combine these two statements I've put together into a single statement.</p>
  
  <p>My first statement is in effect 3 statements in where I only want the first statement that returns a value to be returned, which works a treat.</p>
  
  <pre><code>SELECT ReferenceKey, ReferenceValue FROM
  (   
      SELECT a.GBNK076 AS ReferenceKey, TRIM(a.GBNK076) ||' - '||  b.BANM11 AS ReferenceValue, 1 as preference 
      FROM THTFU.THAP076P AS a LEFT OUTER JOIN OSLTHLF3.CSP11  AS b ON  b.BANK11 = a.GBNK076  AND b.CONO11 = a.CONO076 
      WHERE a.CONO076 = '01' AND a.PMTH076 = 'BMG' AND a.CURN076 = 'EUR'  
      UNION
      SELECT a.GBNK076 AS ReferenceKey, TRIM(a.GBNK076) ||' - '||  b.BANM11 AS ReferenceValue, 3 as preference 
      FROM THTFU.THAP076P AS a LEFT OUTER JOIN  OSLTHLF3.CSP11  AS b ON  b.BANK11 = a.GBNK076 AND b.CONO11 = a.CONO076 
      WHERE a.CONO076 = '01' AND a.PMTH076 = 'BMG' AND a.CURN076 = ''
      UNION
      SELECT a.GBNK076 AS ReferenceKey, TRIM(a.GBNK076) ||' - '||  b.BANM11 AS ReferenceValue, 3 as preference 
      FROM THTFU.THAP076P AS a LEFT OUTER JOIN  OSLTHLF3.CSP11  AS b ON  b.BANK11 = a.GBNK076 AND b.CONO11 = a.CONO076 
      WHERE a.CONO076 = '01' AND a.PMTH076 = '' AND a.CURN076 = ''
  )BankPayingFrom ORDER BY preference
  FETCH FIRST 1 ROWS ONLY
  </code></pre>
  
  <p>However, if none of these three statements return any information I want to be able fire off the SQL statement below to retrieve all possible records.</p>
  
  <pre><code>SELECT BANK11 as ReferenceKey, TRIM(BANK11) ||' - '|| BANM11 as ReferenceValue From OSLTHLF3.CSP11 WHERE CONO11 = '01'
  </code></pre>
  
  <p>How do I join both these statements together so that I need only make one call from my web service to the back end database (AS/400 DB2 database)?</p>
  
  <p>I’d appreciate any assistance.</p>
  
  <p>Many thanks
  Christian</p>