Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: exclude par...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3552 of 3797
Post > Topic >>

Re: exclude part of result

by postgresql@[EMAIL PROTECTED] (Tarlika Elisabeth Schmitz) Jun 27, 2008 at 12:22 PM

On Fri, 27 Jun 2008 11:33:07 +0200
Harald ****hs <hari.****hs@[EMAIL PROTECTED]
> wrote:

> In article <20080627075136.12add021@[EMAIL PROTECTED]
>,
> Tarlika Elisabeth Schmitz <postgresql@[EMAIL PROTECTED]
> 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


Harald, Marc - thank you for your responses! That does the trick.

The USING construct was new to me. I notice from the manual that it is
is equivalent to ON (t1.a = t2.a AND t1.b = t2.b AND t1.c = t2.c).



My objective is to insert the missing a,b,c combinations into
NAVIGATION:
INSERT INTO navigation (a, b, c, save_time, item_no)
SELECT ...

I need to replicate the above for 
a,b,c + a,b + a:

NAVIGATION will really contain
100 - - 11
100 200 - 11
100 200 300 5
100 200 301 6


Some other questions spring to mind:
Which indices should I define? PRODUCT has a few thousand rows, ITEM
will grow over time, NAVIGATION will have a few hundred entries.






-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 1 Posts in Topic:
Re: exclude part of result
postgresql@[EMAIL PROTECT  2008-06-27 12:22:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 11:20:58 CST 2008.