How to get more details from a group by query.

From: Raffaele D'Alba <raffaeledalba_at_libero.it>
Date: Sat, 21 Jul 2001 21:42:43 GMT
Message-ID: <Z%UO6.19235$h9.1622758_at_news.infostrada.it>


How to get more details from a group by query.

[Quoted] consider two tables like:

[Quoted] Object     id_Object  number,
[Quoted] [Quoted]                code          varchar2(10)

[Quoted] RevObj     id_RevObj     number,
[Quoted]                  id_Object      number,
                 code              varchar2(10),
                 RevDate         date

linked with a foreign key in the column id_Object

I need to select for each object the last revision, and with the date I need [Quoted] to obtain also all the data archived in the selected record included the [Quoted] id_RevObj and the code

[Quoted] if I try with a query like this:

[Quoted] [Quoted] select a.id_Object,a.code,max(b.RevDate) RevDate from Object a, RevObj b
where a.id_Object=b.id_Object
[Quoted] group by a.id_Object,a.code

[Quoted] but to get the other details of RevObj I need to add an other level of joint with the table

[Quoted] [Quoted] I thought to order the results by RevDate (desc) and add the where condition [Quoted] [Quoted] rownum=1, but this tecnique doesn't work because the query engine sorts the [Quoted] records only after the results of the where filter.

[Quoted] I curretly use Oracle 7.3.4

[Quoted] [Quoted] Anybody knows an other tecnique more simple ad direct? [Quoted] Thanks in advance,

--
Raffaele D'Alba
Received on Sat Jul 21 2001 - 23:42:43 CEST

Original text of this message