$sql="SELECT student_values.stu_id, student.stu_name, student.stu_lanme, student.stu_clase, student.stu_room, student_values.v_id, values12.v_name, student_values.teacher_id, teacher_admin.teacher_name, teacher_admin.teacher_lname, teacher_admin.type, teacher_admin.loginlast, student_values.sv_date, student_values.sv_mouth, student_values.sv_year, student_values.sv_time
FROM ((student INNER JOIN student_values ON student.stu_id = student_values.stu_id) INNER JOIN teacher_admin ON student_values.teacher_id = teacher_admin.teacher_id) INNER JOIN values12 ON student_values.v_id = values12.v_id WHERE student_values.stu_id like '%$textfield%' AND student.stu_name like '%$textfield2%' AND student.stu_lanme like '%$textfield3%' AND student.stu_clase like '%$stu_clase%' AND student.stu_room like '%$textfield4%' ORDER BY student_values.stu_id ASC";
SELECT distinct student_values.stu_id, student.stu_name, student.stu_lanme, student.stu_clase, student.stu_room, student_values.v_id, values12.v_name, student_values.teacher_id, teacher_admin.teacher_name, teacher_admin.teacher_lname, teacher_admin.type, teacher_admin.loginlast, student_values.sv_date, student_values.sv_mouth, student_values.sv_year, student_values.sv_time ,(select count(*) from student_values where stu_id = student.stu_id and v_id = student_values.v_id) as count_id
FROM ((student
INNER JOIN student_values ON student.stu_id = student_values.stu_id)
INNER JOIN teacher_admin ON student_values.teacher_id = teacher_admin.teacher_id)
INNER JOIN values12 ON student_values.v_id = values12.v_id
WHERE student_values.stu_id LIKE '%$textfield%' AND student.stu_name LIKE '%$textfield2%' AND student.stu_lanme LIKE '%$textfield3%' AND student.stu_clase LIKE '%$stu_clase%' AND student.stu_room LIKE '%$textfield4%'
ORDER BY student_values.stu_id ASC
SELECT student_values.stu_id, student.stu_name, student.stu_lanme, student.stu_clase, student.stu_room, student_values.v_id, values12.v_name, student_values.teacher_id, teacher_admin.teacher_name, teacher_admin.teacher_lname, teacher_admin.type, teacher_admin.loginlast, student_values.sv_date, student_values.sv_mouth, student_values.sv_year, student_values.sv_time ,count(*) as count_id
FROM ((student
INNER JOIN student_values ON student.stu_id = student_values.stu_id)
INNER JOIN teacher_admin ON student_values.teacher_id = teacher_admin.teacher_id)
INNER JOIN values12 ON student_values.v_id = values12.v_id
WHERE student_values.stu_id LIKE '%$textfield%' AND student.stu_name LIKE '%$textfield2%' AND student.stu_lanme LIKE '%$textfield3%' AND student.stu_clase LIKE '%$stu_clase%' AND student.stu_room LIKE '%$textfield4%'
group by student_values.stu_id, student.stu_name, student.stu_lanme, student.stu_clase, student.stu_room, student_values.v_id, values12.v_name, student_values.teacher_id, teacher_admin.teacher_name, teacher_admin.teacher_lname, teacher_admin.type, teacher_admin.loginlast, student_values.sv_date, student_values.sv_mouth, student_values.sv_year, student_values.sv_time
SELECT distinct student_values.stu_id, student.stu_name, student.stu_lanme, student.stu_clase, student.stu_room, student_values.v_id, values12.v_name, student_values.teacher_id, teacher_admin.teacher_name, teacher_admin.teacher_lname, teacher_admin.type, teacher_admin.loginlast, student_values.sv_date, student_values.sv_mouth, student_values.sv_year, student_values.sv_time
แก้ให้แล้ว ลองๆๆ ,(select count(*) from student_values a where a.stu_id = student.stu_id and a.v_id = student_values.v_id) as count_id
FROM ((student
INNER JOIN student_values ON student.stu_id = student_values.stu_id)
INNER JOIN teacher_admin ON student_values.teacher_id = teacher_admin.teacher_id)
INNER JOIN values12 ON student_values.v_id = values12.v_id
WHERE student_values.stu_id LIKE '%$textfield%' AND student.stu_name LIKE '%$textfield2%' AND student.stu_lanme LIKE '%$textfield3%' AND student.stu_clase LIKE '%$stu_clase%' AND student.stu_room LIKE '%$textfield4%'
ORDER BY student_values.stu_id ASC
ด้วยผมไม่รู้ว่า Database Server เป็นอะไร MySql หรือ SqlServer เลยเขียนแบบกลางๆ นะครับ
อันดับแรกคุณต้องหาค่าจำนวนที่ซ้ำก่อน ซึ่งเป็น main detail select stu_id, v_id, count(v_id) count_V from student_value group by stu_id
from ( select stu_id, v_id, count(v_id) count_V from student_value group by stu_id) as TB1 left join student_values as SV
on sv.stu_id = TB1.stu_id
) as TB2
LEFT JOIN student on student.stu_id = TB2.stu_id
LEFT JOIN teacher_admin ON teacher_admin.teacher_id = TB2.teacher_id
LEFT JOIN values12 ON values12.v_id = TB2.v_id
ส่วน ต้องการบางเรคคอร์ดที่ต้องการก็ใส่ where clause ลงไป เข่น
WHERE TB2.stu_id like '%$textfield%'
AND student.stu_name like '%$textfield2%'
AND student.stu_lanme like '%$textfield3%'
AND student.stu_clase like '%$stu_clase%'
AND student.stu_room like '%$textfield4%'
รวมถึงการจัดเรียง
ORDER BY TB2.stu_id ASC; // จัดเรียง ASC ไม่จำเป็น เพราะ มันเรียง เหมือน กับ group by อยู่แล้วครับ