title: Postgres - using select statement inside CASE WHEN
body: <p>Inside case when condition I am executing select statement &amp; if returns anything then I need to get it's value but I am getting error </p>
  
  <pre><code>ERROR:  missing FROM-clause entry for table "us"
  </code></pre>
  
  <p>query is..</p>
  
  <pre><code>SELECT u.user_id,
         CASE
             WHEN
                    (SELECT us.attr_value
                     FROM user_setting us
                     WHERE us.user_id = u.user_id) IS NOT NULL THEN us.attr_value
             ELSE
                    (SELECT gus.attr_value
                     FROM global_user_setting gus
                     WHERE gus.attr_key='key')
         END
  FROM user u
  WHERE u.user_id IN (1,
                            2,3)
  </code></pre>
  
  <p>Error comes at <code>IS NOT NULL THEN us.attr_value</code> I understood the issue but couldn't find how to get that value outside select statement?</p>