title: How to use join between two tables correctly in sql I have an exception
body: <p>I've faced a problems with sql queries, and I need your help plz :(.
  In my code I want to display the names of students from c#Log when entering the id of this course this is the c#Log table : <a href="https://dl.dropboxusercontent.com/u/108513041/Screenshot%20from%202013-06-23%2012:29:47.png" rel="nofollow">HERE</a> 
  and this is the courses table :<a href="https://dl.dropboxusercontent.com/u/108513041/Screenshot%20from%202013-06-23%2012:30:05.png" rel="nofollow">HERE</a> </p>
  
  <p>This is my code :</p>
  
  <pre><code>public void searchRows() throws ClassNotFoundException, SQLException
  
  {   
       String logName=null;
       Class.forName("com.mysql.jdbc.Driver");
       Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/psd_DB?"
                + "user=root&amp;password=123");
  
         Scanner s=new Scanner(System.in);
         System.out.println("Enter the course id you want to display its log:");
         courseId=Integer.parseInt(s.nextLine());
  
         PreparedStatement st1 = (PreparedStatement) con.prepareStatement(" SELECT * FROM courses WHERE courseId="+courseId);
         ResultSet r=(ResultSet) st1.executeQuery();
         while(r.next())
  
         {
             logName=r.getString("courseName")+"Log";
         }
  
         //System.out.println(logName);
  
         PreparedStatement st2 = (PreparedStatement) con.prepareStatement("SELECT "+logName+"."+"studentName FROM "+logName+" INNER JOIN courses ON "+logName+"."+courseId+"="+"courses."+courseId+";");
         st2.executeQuery();
  
  }
  </code></pre>
  
  <p>when I've entered 2 , the output is this exception :</p>
  
  <p><em>Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'C' in 'field list'</em></p>