User Tools

Site Tools


kurs:correlated_subquery
select first_name, last_name, e.employee_id, c from employees e,
(select employee_id, count(employee_id) c from job_history 
group by employee_id 
having count(employee_id) >= 2) g
where e.employee_id = g.employee_id

select first_name, last_name, employee_id from employees e
where (select count(*) from job_history where employee_id = e.employee_id) >= 2 


select  first_name, last_name from employees e where
-- employee_id in (select manager_id from employees where e.employee_id = manager_id)
exists (select 1 from employees where e.employee_id = manager_id)
select first_name, last_name, e.employee_id, c from employees e,
(select employee_id, count(employee_id) c from job_history 
group by employee_id 
having count(employee_id) >= 2) g
where e.employee_id = g.employee_id

select first_name, last_name, employee_id from employees e
where (select count(*) from job_history where employee_id = e.employee_id) >= 2 
select * from (
SELECT tst_fahrzeuge.fhz_name, count(tst_extras.ext_name) c
  FROM tst_extras, tst_fahrzeuge, tst_fhz_ext_int
 WHERE (    (tst_extras.ext_id = tst_fhz_ext_int.fei_ext_id)
        AND (tst_fahrzeuge.fhz_id = tst_fhz_ext_int.fei_fhz_id)
       )
group by fhz_name     
) where c > 1


select fhz_name from tst_fahrzeuge outer 
where (
SELECT count(ext_name) c
  FROM tst_extras, tst_fahrzeuge inner, tst_fhz_ext_int
 WHERE (    (ext_id = fei_ext_id)
        AND (inner.fhz_id = fei_fhz_id)
        and  outer.fhz_name = inner.fhz_name
       )) > 1
kurs/correlated_subquery.txt · Last modified: 2014/09/10 21:22 (external edit)