Re: Sql Query

From: rob <rob_at_dsdelft.nl>
Date: Wed, 10 Oct 2001 09:34:37 +0200
Message-ID: <9q0tlv$16$1_at_news.tudelft.nl>


> hello!
> i used the following query for getting the second highest earner in the
 emp table.
> select * from emp e where 1=(select count(*) from emp where e.sal<sal);
> can someone explain to me the working of the query

Let me give it a try.
For every record in emp (e) the subselect is executed. In the subselect the number of records with a sal larger than the sal in your main select (e.sal) are counted. If the number of records in the subselect = 1 there is only one record with a sal larger than the sal in the main select. There is a problem with this : imagene having a million records in sal , the subselect will be executed 1 million times.

Rob Received on Wed Oct 10 2001 - 09:34:37 CEST

Original text of this message