From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject:
Date: 2012-09-23 00:15:14
Message-ID: CAAY=A7_meqy6Ez80rNaAw+gZ1ZCkJOz=jxPw9dgTGR6Z1fg4kQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have the following query:

SELECT

sem_clave,

to_char(secc_esp_media.sem_fechareg,'TMMon-DD-YYYY') as sem_fechareg,

sem_seccion,

sem_titulo,

sem_enca,

tmd_nombre,

tmd_archivo,

tmd_origen,

gen_nombre,

smd_nombre,

prm_urlyoutube,

prm_prmyoutube,

prm_urlsoundcloud,

prm_prmsoundcloud

FROM secc_esp_media

INNER JOIN cat_tit_media ON tmd_clave = sem_titulo

INNER JOIN cat_secc_media ON smd_clave = sem_seccion

INNER JOIN cat_generos ON gen_clave = tmd_genero

INNER JOIN parametros ON 1 = 1

WHERE

smd_nombre = 'SOMETHING' AND

sem_fipub <= 'SOME DATE'
ORDER BY sem_fipub DESC, sem_ffpub DESC

I thought it was working fine until I noticed I needed to include a
DISTINCT clause as follows:

SELECT DISTINCT ON (sem_clave) ......(the rest of the query is exactly the
same as above)

But, when I run it, I get a message telling me that I need an ORDER BY the
field "sem_clave" which is the field in the DISTINCT clause. How can I
solve this issue without affecting the ORDER BY it already has ?

Regards,
Jorge Maldonado

Responses

  • Re: at 2012-09-23 01:50:43 from David Johnston

Browse pgsql-sql by date

  From Date Subject
Next Message David Johnston 2012-09-23 01:50:43 Re:
Previous Message Wayne Cuddy 2012-09-22 17:34:31 transactions and ecpg