Обсуждение: Advice on re-writing a SELECT query.

Поиск
Список
Период
Сортировка

Advice on re-writing a SELECT query.

От
JORGE MALDONADO
Дата:
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





Re: Advice on re-writing a SELECT query.

От
Marc Mamin
Дата:
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">I have a query like this:<br /> ><br
/>>SELECT<br /> >lpt_titulo AS tmt_titulo,<br /> >tmd_nombre AS tmt_nombre,<br /> >tmd_album AS
tmt_album<br/> >SUM(lpt_puntos) AS tmt_puntos,<br /> >lpt_fuente AS tmt_fuente<br /> >FROM listas_pre_titulos,
temp_lista_titulos<br/> >WHERE <br /> >listas_pre_titulos.lpt_tipo = 3 AND<br />
>listas_pre_titulos.lpt_titulo<> temp_lista_titulos.tmt_titulo AND<br /> >listas_pre_titulos.tmd_album
<>temp_lista_titulos.tmt_album AND<br /> >listas_pre_titulos.lpt_fuente <>
temp_lista_titulos.tmt_fuente<br/> >GROUP BY <br /> >lpt_fuente, lpt_titulo, tmd_album<br /> >ORDER BY
tmt_puntosASC<br /> ><br /> >Is it valid to re-write the FROM and WHERE statements as follows?<br /> ><br />
>FROMlistas_pre_titulos<br /> >INNER JOIN temp_lista_titulos ON <br /> >(listas_pre_titulos.lpt_titulo,
listas_pre_titulos.tmd_album,listas_pre_titulos.lpt_fuente) <br /> >NOT IN <br />
>(temp_lista_titulos.tmt_titulo,temp_lista_titulos.tmt_album, temp_lista_titulos.tmt_fuente)<br /> >WHERE
listas_pre_titulos.lpt_tipo= 3<br /><br /> hello, <br /> your second syntax is not valid sql, but you can achieve it as
inthis example:<br /><br /> create temp table a(a int,b int,c int,d int);<br /> create temp table b(a int,b int,c int,d
int);<br/><br /> select * from a join b ON ((a.a,a.b,a.c)<>(b.a,b.b,b.c))<br /><br /> but beware if null values
areinvolved( 1<>NULL => NULL).<br /> In this case you can use :<br /> select * from a join b ON ((a.a,a.b,a.c)
ISDISTINCT FROM (b.a,b.b,b.c))<br /><br /> regards,<br /><br /> Marc Mamin<br /><br /></div>