I have lots of tables that I need to join/query at the one time. I have something like this : $sql = "SELECT ProgrammingFoundations.student_id, ProgrammingFoundations.total_PF_attendance, InformationSystems.total_IS_attendance, Machines.total_M_attendance FROM ProgrammingFoundations, InformationSystems, Machines Where ProgrammingFoundations.student_id = InformationSystems.student_id and ProgrammingFoundations.student_id = Machines.student_id and InformationSystems.student_id = Machines.student_id; Code (markup): Is there a simpler way to write Where ProgrammingFoundations.student_id = InformationSystems.student_id and ProgrammingFoundations.student_id = Machines.student_id and InformationSystems.student_id = Machines.student_id; Code (markup): As I have more tables I need to add to this query and there would be a LOT of ANDs.
By the transitive relation of your tables on the student_id field the 3rd line of your WHERE clause is redundant/unnecessary. If a=b and b=c, you don't need to state that a=c. All the where clause needs to say is Where ProgrammingFoundations.student_id = InformationSystems.student_id and ProgrammingFoundations.student_id = Machines.student_id PHP:
$sql = "SELECT PF.student_id, PF.total_PF_attendance, IS.total_IS_attendance, M.total_M_attendance FROM ProgrammingFoundations PF, InformationSystems IS, Machines M Where PF.student_id = IS.student_id and PF.student_id = M.student_id; Code (markup):
$sql = "SELECT ProgrammingFoundations.student_id, ProgrammingFoundations.total_PF_attendance, InformationSystems.total_IS_attendance, Machines.total_M_attendance FROM ProgrammingFoundations JOIN InformationSystems USING(student_id) JOIN Machines USING(student_id)"; PHP: Regards