Код: Выделить всё
select *
from A
inner join B on (A.ad_no=B.ad_no)
where B.ad_no in (
select ad_no
from A
where $staff!='00:00' and $staff!='0:00'
)
order by B.ctype asc, B.cname asc,B.ad_no asc
Подробнее здесь: https://stackoverflow.com/questions/469 ... n-subquery