mysql的复杂选择查询将两列与where子句组合在一起

时间:2012-12-07 07:23:43

标签: mysql select join

我有两张表,比如

表1:FACULTY_DETAILS

fac_det_id (pk)........ fname ........... 可用性 < / p>

..... 1 ......................... xxx ............... ..完整的时间

..... 2 ......................... yyy ............... ..部分时间

..... 3 ......................... zzz ............... ..weekdays

..... 4 ......................... aaa ............... ..partime

表2:FACULTY

faculty_id (PK)..........的 COURSE_ID ........的 fac_det_id (FK )

..... 1 .............................. 1 .......... ............ 2

..... 2 .............................. 2 .......... ............ 3

..... 3 .............................. 3 .......... ............ 1

..... 4 .............................. 4 .......... ............ 3

..... 5 .............................. 3 .......... ............ 4

当我给出课程ID时 我需要fname,table1中的可用性和表2中的faculty_id

即如果我给出course_id = 3那么我需要

faculty_id ..........的 FNAME ...........的资格

..... 2 ................... xxx ................全职

..... 5 ................... AAA ................ partime

3 个答案:

答案 0 :(得分:0)

试试这个:

SELECT f.faculty_id, fd.fname, fd.availability  qualification 
FROM FACULTY f 
INNER JOIN FACULTY_DETAILS fd ON f.fac_det_id = fd.fac_det_id 
WHERE f.course_id = 3

答案 1 :(得分:0)

您可以使用:

SELECT faculty_id, fname, availibility AS qualification
FROM faculty a, faculty_details b
WHERE a.fac_det_id = b.fac_det_id AND course_id = $your_course_id;

答案 2 :(得分:0)

这应该有效

select f.faculty_id,fd.fname,fd.availability as qualification
from faculty f,faculty_details fd
inner join  faculty_details fd ON f.fac_det_id = fd.fac_det_id 
where course_id=3;