0

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->fields('student_master', array('reg_no','name','dob','dept_code','degree','batch_year'));
$query->condition('dept_code',$dept,'=') AND $query->condition('batch_year',$batch,'=');
$query->orderBy('reg_no','ASC') ;
$results = $query->execute();

Table : semester_appear

$sem_query = db_select('semester_appear');
$sem_query->fields('semester_appear', array('reg_no','batch_year','month','year','subject_code','sub_serial_no','semester_appear'));
$sem_query->distinct();
$sem_query->condition('year',$year,'=') AND $sem_query->condition('reg_no',$reg1,'=') AND $sem_query->condition('semester_appear',$semester,'=') AND $sem_query->condition('month',$month,'=') AND $sem_query->condition('marks_updated',$no,'=') AND $sem_query->condition('batch_year',$batch,'=') ;
$subject_results = $sem_query->execute();

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.