I have two tables one is named as teacher-record and other is student record teacher-record has columns teacher_id,email(email of teacher) like this student-record has two columns student_id,email(email of student) i trying to select teacher_id and student_id using single query for that i am using union
mysql query i used for above purpose is like this also i using codeignitor
public function get_std_tech_id($std_email,$tech_email)
$query = $this->db->query("SELECT `student_id` AS std FROM `student-record` WHERE `email`= '$std_email' UNION ALL SELECT `teacher_id` AS tech FROM `teacher-record` WHERE `email` ='$tech_email'");
UNION won't allow you this, it needs same column name.
You can add a 2nd column containing what type of id that specific row contains:
SELECT `student_id` AS id, 'std' AS type FROM `student-record` WHERE `email`= '$std_email' UNION ALL SELECT `teacher_id` AS id, 'tech' AS type FROM `teacher-record` WHERE `email` ='$tech_email'
then in php you can differentiate the results based on the column
PS: I am not a PHP guy so I can't predict in what format this dataset will come.