User Tools

Site Tools


kurs:correlated_subquery

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
kurs:correlated_subquery [2009/09/24 14:37]
mh
kurs:correlated_subquery [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +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)
 +</​code>​
 +
 +<​code>​
 +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 
 +</​code>​
 +
 +<​code>​
 +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
 +</​code>​
kurs/correlated_subquery.txt ยท Last modified: 2014/09/10 21:22 (external edit)