Re: [GENERAL] I don't understand something...

2011-10-03 Thread Alban Hertroys
On 3 October 2011 08:33, Alexander Pyhalov wrote: > Now we want to select count of all employees who doesn't have any > subordinates (query 1): >  SELECT count(employee_id) from employees o where not exists  (select 1 from > employees  where manager_id=o.employee_id); >  count > --- >    89 >

Re: [GENERAL] I don't understand something...

2011-10-03 Thread hubert depesz lubaczewski
On Mon, Oct 03, 2011 at 11:48:45AM +0400, Alexander Pyhalov wrote: > On 10/03/2011 11:19, Achilleas Mantzios wrote: > >Alexander, that's a classic one, > >rewrite your last query as : > > > >SELECT count(employee_id) from employees where employee_id not in > > (select manager_id from employees

Re: [GENERAL] I don't understand something...

2011-10-03 Thread Alexander Pyhalov
On 10/03/2011 11:19, Achilleas Mantzios wrote: Alexander, that's a classic one, rewrite your last query as : SELECT count(employee_id) from employees where employee_id not in (select manager_id from employees WHERE manager_id IS NOT NULL); NULLS semantics are sometimes not so obvious.

Re: [GENERAL] I don't understand something...

2011-10-03 Thread Achilleas Mantzios
Alexander, that's a classic one, rewrite your last query as : SELECT count(employee_id) from employees where employee_id not in (select manager_id from employees WHERE manager_id IS NOT NULL); NULLS semantics are sometimes not so obvious. Στις Monday 03 October 2011 09:33:12 ο/η Alexan

[GENERAL] I don't understand something...

2011-10-02 Thread Alexander Pyhalov
Hello. I was asked a simple question. We have table employees: \d employees Table "public.employees" Column |Type | Modifiers +-+-