title: How to use CASE clause (DB2) to display values from a different table?
body: <p>I'm working in a bank so I had to adjust the column names and information in the query to fit the external web, so if there're any weird mistakes know it is somewhat fine.</p>
  
  <p>I'm trying to use the CASE clause to display data from a different table, I know this is a workaround but due to certain circumstances I'm obligated to use it, plus it is becoming interesting to figure out if there's an actual solution.</p>
  
  <p>The error I'm receiving for the following query is:</p>
  
  <blockquote>
    <p>"ERROR [21000] [IBM][CLI Driver][DB2] SQL0811N The result of a scalar
    fullselect, SELECT INTO statement, or VALUES INTO statement is more
    than one row."</p>
  </blockquote>
  
  <pre><code>select  bank_num, branch_num, account_num, client_id,
  CASE
      WHEN exists(
          select *
          from bank.services BS
          where ACCS.client_id= BS.sifrur_lakoach
          )
  
      THEN (select username from bank.services BS where BS.client_id = ACCS.client_id)
          ELSE 'NONE'
              END username_new
  from bank.accounts accs
  where bank_num = 431 and branch_num = 170
  </code></pre>
  
  <p><strong>EDIT:</strong>
  AFAIK we're using DB2 v9.7:
  DSN11015 - DB21085I  Instance "DB2" uses "64" bits and DB2 code release "SQL09075" with
  level identifier "08060107".
  Informational tokens are "DB2 v9.7.500.702", "s111017", "IP23287", and Fix Pack "5".</p>