Path: utzoo!attcan!uunet!mailrus!ncar!tank!delphi!monty From: monty@delphi.uchicago.edu (Monty Mullig) Newsgroups: comp.databases Subject: Re: Simple SQL question Keywords: SQL Message-ID: <6518@tank.uchicago.edu> Date: 2 Dec 89 17:57:44 GMT References: <98813@ti-csl.csc.ti.com> <2510@bilpin.UUCP> Sender: news@tank.uchicago.edu Reply-To: monty@delphi.UUCP (Monty Mullig) Organization: Univ. of Chicago, BSD Info. Systems Lines: 31 In article <2510@bilpin.UUCP> jim@bilpin.UUCP (JimG) writes: > IN ARTICLE <98813@ti-csl.csc.ti.com>, > hemphill@csc000.csc.ti.com (Charles Hemphill) WRITES: > >> Can the following type of question be answered with an SQL expression? >> >> List the 10 oldest employees. >> > > It can be done in one SQL statement as follows : > > SELECT * FROM tablename tablealias > WHERE 10 > ( SELECT COUNT(*) FROM tablename > WHERE tablename.age > tablealias.age > ) > > Now isn't that neat? you mean, a statement like this: select * from master m1, master m2 where 10 > (select count(*) from m1 where m1.bdate < m2.bdate); funny, but INGRES (5.0) on my machine choked on this query. now, is INGRES at fault or is the SQL wrong ? --monty Brought to you by Super Global Mega Corp .com