title: Query using CASE, WHEN, THEN in postgresql not working
body: <p>I have three tables, <code>tbl_doctors_details</code>, <code>tbl_time</code> and <code>tbl_token</code>.</p>
  
  <p>I have to select the details from <code>tbl_time</code> or <code>tbl_token</code>. That is if for particular doctor in hospital have <code>t_type</code> is <code>time</code> then select from <code>tbl_time</code> else select from <code>tbl_token</code>.</p>
  
  <p>For example, for <code>doctor_id</code> is 100 and <code>hospital_id</code> 1, the <code>t_type</code> is <code>time</code>. So for this user, details should select from <code>tbl_time</code> table.</p>
  
  <p>Below is the sample structure and data of three tables:</p>
  
  <p><a href="https://i.stack.imgur.com/xB2dd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xB2dd.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/p5k5R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p5k5R.png" alt="enter image description here"></a></p>
  
  <p>How can I use <strong>CASE</strong> condition in query here?</p>
  
  <p>I tried:</p>
  
  <pre><code>SELECT *
  FROM 
  ( SELECT * CASE WHEN t_type= 'time'  FROM dbname.tbl_doctors_details t1 THEN
             dbname.tbl_time t2
             ELSE
             dbname.tbl_token t2
             WHERE t1.hospital_id=t2.hospital_id AND t1.doctor_id=t2.doctor_id);
  </code></pre>
  
  <p>I know the query is not working, but how can I make the query working?</p>