Skip site navigation (1) Skip section navigation (2)

Re: exclude part of result

From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: exclude part of result
Date: 2008-06-27 09:33:07
Message-ID: pubq1nfcj0.fsf@srv.protecting.net (view raw or flat)
Thread:
Lists: pgsql-sql
In article <20080627075136(dot)12add021(at)dick(dot)coachhouse>,
Tarlika Elisabeth Schmitz <postgresql(at)numerixtechnology(dot)de> writes:

> PRODUCT table :

> A B C
> 100 200 300
> 100 200 301
> 100 205 300
> 100 205 301

> NAVIGATION table
> A B C #ITEMS
> 100 200 300 5
> 100 200 301 6

> My query needs to return 
> 100 205 300 #items
> 100 205 301 #items
> so I can insert them in NAVIGATION. NAVIGATION must not contain any
> duplicate combinations of [a,b,c].

Just use another LEFT JOIN to filter out the corresponding product lines:

SELECT DISTINCT a, b, c, now(), count(item_pk) 
FROM product
LEFT JOIN navigation USING (a, b, c)
LEFT JOIN item ON item.product_fk = product_pk
WHERE navigation.a IS NULL
GROUP BY a, b, c


In response to

Responses

pgsql-sql by date

Next:From: Marc MaminDate: 2008-06-27 10:50:03
Subject: Re: exclude part of result
Previous:From: Tarlika Elisabeth SchmitzDate: 2008-06-27 06:51:36
Subject: Re: exclude part of result

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group