select student.student_fname,
student.student_mname,
student.student_lname, logs.time, logs.transaction,logs.entity_type,prof.professor_fname,prof.professor_mname,prof.professor_lname
from student_tbl as student,
logs_tbl as logs,
professor_tbl as prof
where student.student_id=logs.entity_id
and prof.professor_id=logs.entity_id
and logs.date ='$date_today'
and logs.course_id='$course'
and logs.sections_id='$sections'
and logs.rooms_id='$room'
group by logs.date,
logs.term,
logs.course_id,
logs.entity_id
order by logs.logs_id asc
在student_tbl和professor_tbl中,我的student_id和professor_id等于logs_tbl的entity_id。我如何将不同表中的两个id与logs_tbl中的entity_id进行比较?这是唯一给我错误的一条线。或者你有建议吗?除了sql注入的东西
更新
我有 student_tbl 列:student_id,student_fname,student_mname,student_lname。我也有教授_tbl,其中有以下列: professor_id ,professor_fname,professor_mname,professor_lname和我的第三个表,它的所有基础是 logs_tbl 列:entity_id (这是student_id和professor_id将等同的地方),course_id,rooms_id,sections_id,time,date,transaction,entity_type。 这就是我想要展示的内容:
示例数据显示:
答案 0 :(得分:3)
select student.student_fname, student.student_mname, student.student_lname, logs.time, logs.transaction,logs.entity_type
from student_tbl as student inner join logs_tbl as logs on student.student_id=logs.entity_id
where logs.date ='$date_today'
and logs.course_id='$course'
and logs.sections_id='$sections'
and logs.rooms_id='$room'
group by logs.date, logs.term,
logs.course_id,
logs.entity_id
UNION
select prof.professor_fname,prof.professor_mname,prof.professor_lname , logs.time, logs.transaction,logs.entity_type
from professor_tbl as prof inner join logs_tbl as logs on prof.professor_id=logs.entity_id
where logs.date ='$date_today'
and logs.course_id='$course'
and logs.sections_id='$sections'
and logs.rooms_id='$room'
group by logs.date, logs.term,
logs.course_id,
logs.entity_id
答案 1 :(得分:0)
select student.student_fname,student.student_mname,student.student_lname, logs.time, logs.transaction,logs.entity_type,prof.professor_fname,prof.professor_mname,prof.professor_lname
from student_tbl as student
join logs_tbl as logs on student.student_id=logs.entity_id and logs.date ='$date_today' and logs.course_id='$course' and logs.sections_id='$sections' and logs.rooms_id='$room'
join professor_tbl as prof on prof.professor_id=logs.entity_id
group by logs.date, logs.term, logs.course_id, logs.entity_id
order by logs.logs_id asc
您可以使用join
。