title: Using sub queries
body: <p>I am trying to access a data in a table using a sub query. 
  The table 1 contains a foreign key to table 2 , which means i can use that key to access the data in table 2.
  My problem is  after i return the array list from the below shown method , the arraylist is null.</p>
  
  <p>This is what i have done:</p>
  
  <pre><code>     LogEntry logBookDates;
      List&lt;LogEntry&gt; bookList =new ArrayList();
   try{
   PreparedStatement getSummaryStmt=con.prepareStatement("SELECT * FROM LOGENTRYTABLE WHERE DIARYCODE =(SELECT Diarycode FROM LOGBOOKTABLE WHERE STUDENTUSERNAME=? OR SUPERVISORUSERNAME=? AND PROJECT_APPROVE_STATUS=?)");
  
  //the above statment is the sub query which i have created, i get the diary code from   log book table and then access the log entry table.
  
  
  
    getSummaryStmt.setString(1,userName);
    getSummaryStmt.setString(2,userName);
    getSummaryStmt.setString(3,"Accepted");
    ResultSet rs=getSummaryStmt.executeQuery();
    while(rs.next())
   {
       logBookDates=new LogEntry(rs.getString("STUDENTUSERNAME"),rs.getString("SupervisorUsername"),rs.getString("projecttitle"),rs.getString("projectDescription"),rs.getDate("startDate"),rs.getDate("enddate"),rs.getString("project_approve_status"),rs.getString("diarycode"),rs.getString("projectcode"),rs.getInt("Index"),rs.getString("log_Entry"),rs.getDate("logentry_date"),rs.getString("supervisor_comment"),rs.getString("project_progress"));
       bookList.add(logBookDates);
   }
  
   }catch(Exception e){}
   return bookList;
   }
  </code></pre>
  
  <p>I have not used sub queries before and this is the first time am using them.
  What seems to be the problem here ?</p>
  
  <p>Thank you for your time.</p>
  
  <p>Edit : Sample data of logbook table
  <img src="https://i.stack.imgur.com/6xJxA.png" alt="enter image description here"></p>
  
  <p>Sample Data of logentry table 
  <img src="https://i.stack.imgur.com/7Rj1A.png" alt="enter image description here"></p>
  
  <p>Expected output:</p>
  
  <p>I don't have a screen shot of that but what i need is just to iterate through the arraylist which will be returned from the above method.</p>