帮助内部联接查询

时间:2011-08-22 06:28:40

标签: php mysql

我有两个问题

$query1="SELECT staffid, COUNT(staffid) FROM enrll GROUP BY staffid ORDER BY COUNT(staffid) DESC";
$query2="SELECT staffid FROM staff as s WHERE auth = '1' AND NOT EXISTS ( SELECT staffid from shdl as h where s.staffid=h.staffid and h.shdldt='".$unixdt."')";

两个查询都在数组中返回值,我想从查询1中找出那些具有查询2的内部联接的值,并且值将在数组中。

注意两个查询的组合查询将返回最终查询。

1 个答案:

答案 0 :(得分:1)

select e.staffid, count(e.staffid)
from enrll e
join staff s on e.staffid=s.staffid
where s.auth = '1' and NOT EXISTS ( 
    SELECT staffid from shdl as h 
    where s.staffid=h.staffid and h.shdldt='$unixdt')
group by e.staffid
ORDER BY COUNT(staffid) DESC