Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Multiple LEFT JOIN in PostgreSQL

$
0
0

I got a “nice” problem with a query in PostgreSQL with a multiple join

SELECT DISTINCT
"Monitoraggio_L001_L008_2015_aprile"."ID",
"Monitoraggio_L001_L008_2015_aprile"."Ordine",
"Monitoraggio_L001_L008_2015_aprile"."DataOrd",
"GeoLocalita"."Latitudine",
"GeoLocalita"."Longitudine"

FROM "Monitoraggio_L001_L008_2015_aprile" 

LEFT OUTER JOIN "Clienti" ON
"Monitoraggio_L001_L008_2015_aprile"."IDPartner" = "Clienti"."IDPartner"

LEFT OUTER JOIN "GeoLocalita" ON
"Clienti"."ID" = "GeoLocalita"."IDCliente"

WHERE "GeoLocalita"."Selezionato" = True 
AND "Clienti"."Ruolo" IN ('Cliente','Cliente e fornitore')

I have tried also this kind of sintax:

SELECT DISTINCT
"Monitoraggio_L001_L008_2015_aprile"."ID",
"Monitoraggio_L001_L008_2015_aprile"."Ordine",
"Monitoraggio_L001_L008_2015_aprile"."DataOrd",
"GeoLocalita"."Latitudine",
"GeoLocalita"."Longitudine"

FROM "Monitoraggio_L001_L008_2015_aprile" m,
"Clienti" c,
"GeoLocalita" g

WHERE m."IDPartner" = c."IDPartner"
AND c."ID" = g."IDCliente"
AND "GeoLocalita"."Selezionato" = True 
AND "Clienti"."Ruolo" IN ('Cliente','Cliente e fornitore')

I have seen here http://stackoverflow.com/questions/8779918/postgres-multiple-joins, http://stackoverflow.com/questions/17874873/postgresql-how-to-join-with-multiple-cross-reference-table and many others, but my result is that I get only the fields of the Monitoraggio_L001_L008_2015_aprile table…cannot get also Latitudine and Longitudine…can anyone help me please??


Viewing all articles
Browse latest Browse all 1138

Trending Articles