Advice on re-writing a SELECT query.

From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Advice on re-writing a SELECT query.
Date: 2013-05-25 17:17:20
Message-ID: CAAY=A79boj5cRCr=sxQ5SvozY43qzVSS_iYdZrmssoB_y43jXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a query like this:

SELECT
lpt_titulo AS tmt_titulo,
tmd_nombre AS tmt_nombre,
tmd_album AS tmt_album
SUM(lpt_puntos) AS tmt_puntos,
lpt_fuente AS tmt_fuente
FROM listas_pre_titulos, temp_lista_titulos
WHERE
listas_pre_titulos.lpt_tipo = 3 AND
listas_pre_titulos.lpt_titulo <> temp_lista_titulos.tmt_titulo AND
listas_pre_titulos.tmd_album <> temp_lista_titulos.tmt_album AND
listas_pre_titulos.lpt_fuente <> temp_lista_titulos.tmt_fuente
GROUP BY
lpt_fuente, lpt_titulo, tmd_album
ORDER BY tmt_puntos ASC

Is it valid to re-write the FROM and WHERE statements as follows?

FROM listas_pre_titulos
INNER JOIN temp_lista_titulos ON
(listas_pre_titulos.lpt_titulo, listas_pre_titulos.tmd_album,
listas_pre_titulos.lpt_fuente)
NOT IN
(temp_lista_titulos.tmt_titulo, temp_lista_titulos.tmt_album,
temp_lista_titulos.tmt_fuente)
WHERE listas_pre_titulos.lpt_tipo = 3

With respect,
Jorge Maldonado

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marc Mamin 2013-05-25 17:52:23 Re: Advice on re-writing a SELECT query.
Previous Message Brice André 2013-05-25 12:49:38 Re: DELETE...RETURNING problem with libpq