how to display unique records between two table by using db_select query in drupal The following two tables contained reg_no field. how to get unique reg_no records of the student_master table

for example 

student_master table 

reg_no

MA1001

MA1002

semester_appear table 

reg_no 

MA1001

but I want to get output only MA1002. how to get the output by using following code 

Table : **Student Master**

$query = db_select('student_master');
$query-&gt;fields('student_master', array('reg_no','name','dob','dept_code','degree','batch_year'));
$query-&gt;condition('dept_code',$dept,'=') AND $query-&gt;condition('batch_year',$batch,'=');
$query-&gt;orderBy('reg_no','ASC') ;
$results = $query-&gt;execute();


Table : semester_appear

$sem_query = db_select('semester_appear');
$sem_query-&gt;fields('semester_appear', array('reg_no','batch_year','month','year','subject_code','sub_serial_no','semester_appear'));
$sem_query-&gt;distinct();
$sem_query-&gt;condition('year',$year,'=') AND $sem_query-&gt;condition('reg_no',$reg1,'=') AND $sem_query-&gt;condition('semester_appear',$semester,'=') AND $sem_query-&gt;condition('month',$month,'=') AND $sem_query-&gt;condition('marks_updated',$no,'=') AND $sem_query-&gt;condition('batch_year',$batch,'=') ;
$subject_results = $sem_query-&gt;execute();
I have found that the easiest way to do complex MySQL queries (including JOIN, which is what you're after here) is to use db_query():
https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_query/7

And the MySQL docs explain the JOIN syntax quite nicely:
http://dev.mysql.com/doc/refman/5.0/en/join.html