SELECT `classes`.`id` AS `class_id`, `student_session`.`id` as `student_session_id`, `students`.`id`, `classes`.`class`, `sections`.`id` AS `section_id`, `sections`.`section`, `students`.`id`, `students`.`admission_no`, `students`.`roll_no`, `students`.`admission_date`, `students`.`firstname`, `students`.`middlename`, `students`.`lastname`, `students`.`image`, `students`.`mobileno`, `students`.`email`, `students`.`state`, `students`.`city`, `students`.`pincode`, `students`.`religion`, `students`.`dob`, `students`.`current_address`, `students`.`blood_group`, `students`.`permanent_address`, IFNULL(students.category_id, 0) as `category_id`, IFNULL(categories.category, "") as `category`, `students`.`adhar_no`, `students`.`samagra_id`, `students`.`bank_account_no`, `students`.`cast`, `students`.`bank_name`, `students`.`ifsc_code`, `students`.`guardian_name`, `students`.`guardian_relation`, `students`.`guardian_phone`, `students`.`guardian_address`, `students`.`is_active`, `students`.`created_at`, `students`.`mother_name`, `students`.`updated_at`, `students`.`father_name`, `students`.`rte`, `students`.`gender`, `users`.`id` as `user_tbl_id`, `users`.`username`, `users`.`password` as `user_tbl_password`, `users`.`is_active` as `user_tbl_active`, table_custom_1.field_value as `DIscount Category (per month)`, `table_custom_2`.`field_value` as `AWS`
FROM `students`
LEFT JOIN `custom_field_values` as `table_custom_1` ON `students`.`id` = `table_custom_1`.`belong_table_id` AND `table_custom_1`.`custom_field_id` = 1
LEFT JOIN `custom_field_values` as `table_custom_2` ON `students`.`id` = `table_custom_2`.`belong_table_id` AND `table_custom_2`.`custom_field_id` = 2
JOIN `student_session` ON `student_session`.`student_id` = `students`.`id`
JOIN `classes` ON `student_session`.`class_id` = `classes`.`id`
JOIN `sections` ON `sections`.`id` = `student_session`.`section_id`
LEFT JOIN `categories` ON `students`.`category_id` = `categories`.`id`
LEFT JOIN `users` ON `users`.`user_id` = `students`.`id`
WHERE `student_session`.`session_id` = '19'
AND `users`.`role` = 'student'
AND `students`.`id` IN(1324)
GROUP BY `students`.`id`
ORDER BY `students`.`id`