title: How to retrieve values from Foreign Key table?
body: <p>I'm trying to get the values of each column of my Foreign Key table. So I normalize my table using <strong>Second Normal Form</strong> where I split my tables into two. Picture below.</p>
  
  <p><a href="https://i.stack.imgur.com/cGB2i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cGB2i.png" alt="1st Table"></a></p>
  
  <p>1st Table where my Primary Key is <code>SECTION_ID</code> referencing <code>SECTION_ID</code> in the 2nd Table.</p>
  
  <p><a href="https://i.stack.imgur.com/JZO8d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JZO8d.png" alt="2nd Table"></a></p>
  
  <p>Here where I supply the values for the <code>SECTION_NAME</code> to search if the record exists. What I want to do if the user enter a existing record I want to get all the values of Foreign Key table. How will I do it? </p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      String searchSection = Section_SearchSection_Textfield.getText();
      String searchStudentLimit = Section_Student_Limit_ComboBox.getSelectedItem().toString();
  
      String searchSECTION_NAME = "SELECT * FROM allsections_list WHERE SECTION_NAME = ?";
  
      try (Connection myConn = DBUtil.connect();
               PreparedStatement myFirstPs = myConn.prepareStatement(searchSECTION_NAME);)
          {
               myFirstPs.setString(1, searchSection);
  
               try (ResultSet myRs = myFirstPs.executeQuery())
               {
                   int resultCounter = 0;
                   while (myRs.next())
                   {
                       String mySectionName = myRs.getString(2);//Get the value of SECTION_NAME
                       Section_SectionName_TextField.setText(mySectionName);
                       Section_SectionName_TextField.setEnabled(true);
                       resultCounter++;
                   }
                   if (resultCounter == 1)//If exist
                   {
                       JOptionPane.showMessageDialog(null, "Data Found");
                   }
                   else//If not exist
                       JOptionPane.showMessageDialog(null, "No Data Found");
               }}
  </code></pre>
  
  <p>Do I need to create a another select query for Foreign Key? I think it's no because I just wanna get the values. Correct me if I'm wrong. Feel free to comment. Thanks! :)</p>