help request for sql select

A

Andrea

Hi,

I have the following sql statement on Informix database:

SELECT pr.tipo_pratica, pr.versione, pr.numero_pratica, sa.prg_atto, pr.data_trasmissione, pr.tipo_atto, pr.oggetto
FROM pratica pr
INNER JOIN statoatto sa ON sa.tipo_pratica = pr.tipo_pratica AND sa.versione = pr.versione AND sa.numero_pratica = pr.numero_pratica AND sa.prg_atto = pr.prg_atto
INNER JOIN movimenticapitolo mc ON mc.tipo_pratica = sa.tipo_pratica AND mc.versione = sa.versione AND mc.numero_pratica = sa.numero_pratica AND mc.prg_atto = sa.prg_atto
INNER JOIN gruppocapitolo gc ON gc.num_capitolo = mc.numero_capitolo
INNER JOIN gruppolavoro gl ON gl.id_gruppo = gc.id_gruppo
INNER JOIN gruppoistruttore gi ON gi.id_gruppo = gl.id_gruppo
WHERE gi.cod_fiscale = ? AND sa.cod_stato = ? AND year(pr.data_trasmissione) = ?

this is the output of sql execution:

tipo_pratica - versione - numero_pratica - prg_atto - data_trasmissione - tipo_atto - oggetto
001 01 200 4 2005-10-10 C MOMMMO
001 01 100 2 2005-10-30 B pluto
001 01 100 1 2005-10-29 A pippo

but I want to get only the row with the max value of column sa.prg_atto for each combination of tipo_pratica + versione + numero_pratica,
so the output should be the following:

tipo_pratica - versione - numero_pratica - prg_atto - data_trasmissione - tipo_atto - oggetto
001 01 200 4 2005-10-10 C MOMMMO
001 01 100 2 2005-10-30 B pluto


Somebody can help me?
I tried many times with not success!
Thank in advance.
Regards

Andrea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top