pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: left outer join only select newest record
Date: Wed, 23 May 2012 10:37:31 +0100
Message-ID: <53C6FD0FE48B43C0AD419648FDC8D943@marktestcr.marktest.pt> (raw)
References: <201205231027.39198.gary.stainburn@ringways.co.uk>

Gary,

You describe two tables vehicle stock and tax requests. The former has a 
one-to-many relationship wit the second one, right?

But your query involves stock details and used_diary.

What is the relationship of these two new tables to the previous ones?

Could you please kindly supply an example of what you have and of the 
desired output? For me it would be easier...

Best,
Oliver

----- Original Message ----- 
From: "Gary Stainburn" <gary.stainburn@ringways.co.uk>
To: <pgsql-sql@postgresql.org>
Sent: Wednesday, May 23, 2012 10:27 AM
Subject: [SQL] left outer join only select newest record


> Hi folks,
>
> I know I've seen posts like this before but Google isn't helping today.
>
> I have two tables, vehicle stock and tax requests. Each vehicle can be 
> taxed
> more than once, but I only want to pull in the most recent tax request - 
> the
> one with the highest ud_id.
>
> I have the following, which obviously returning multiple records which 
> then
> appears that the same vehicle is in stock multiple times.  How can I make 
> it
> so we only show each vehicle once, showing the most recent tax request
> details.
>
>
> select * from stock_details s
> left outer join used_diary u on s.s_registration = u.ud_registration;
>
>
> -- 
> Gary Stainburn
> Group I.T. Manager
> Ringways Garages
> http://www.ringways.co.uk
>
> -- 
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql 




view thread (11+ messages)  latest in thread

Message-ID: <53C6FD0FE48B43C0AD419648FDC8D943@marktestcr.marktest.pt>
Permalink:  ../53C6FD0FE48B43C0AD419648FDC8D943@marktestcr.marktest.pt/
Also on:    postgresql.org/message-id/53C6FD0FE48B43C0AD419648FDC8D943@marktestcr.marktest.pt

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: oliveiros.cristina@marktest.pt, gary.stainburn@ringways.co.uk
  Subject: Re: left outer join only select newest record
  In-Reply-To: <53C6FD0FE48B43C0AD419648FDC8D943@marktestcr.marktest.pt>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox