Re: [SQL] left outer join only select newest record

2012-05-24 Thread Oliveiros d'Azevedo Cristina
s d'Azevedo Cristina" To: "Oliveiros d'Azevedo Cristina" ; "Gary Stainburn" ; Sent: Wednesday, May 23, 2012 11:41 AM Subject: Re: [SQL] left outer join only select newest record Sorry, Gary, I made a mistake on the last column. It should be SELECT subq.s

Re: [SQL] left outer join only select newest record

2012-05-24 Thread Gary Stainburn
On Thursday 24 May 2012 09:17:00 Pavel Stehule wrote: > please, WHERE (ud_id, ud_pex_registration) = (SELECT ... > > replace by > > WHERE (..) IN (SELECT .. > > Regards > > Pavel Worked perfectly, thank you -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Se

Re: [SQL] left outer join only select newest record

2012-05-24 Thread Pavel Stehule
> > This was more like what I was thinking, but I still get an error, which I > don't understand.  I have extracted the inner sub-select and it does only > return one record per registration. (The extra criteria is just to ignore old > or cancelled tax requests and doesn't affect the query) > > goo

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
On Wednesday 23 May 2012 10:46:02 Pavel Stehule wrote: > select distinct on (s.s_registration) * > ... order by u.ud_id desc I tried doing this but it complained about the order by. goole=# select distinct on (s.s_stock_no) s_stock_no, s_regno, s_vin, s_created, ud_id, ud_handover_date from sto

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Oliveiros d'Azevedo Cristina
'; GROUP s_stock_no,s_regno,s_vin,s_created ) subq JOIN used_diary sec ON subq.m = sec.ud_id - Original Message - From: "Gary Stainburn" To: Sent: Wednesday, May 23, 2012 10:47 AM Subject: Re: [SQL] left outer join only select newest record Appologies for not making it

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Oliveiros d'Azevedo Cristina
_diary sec ON subq.m = sec.ud_id - Original Message - From: "Gary Stainburn" To: Sent: Wednesday, May 23, 2012 10:47 AM Subject: Re: [SQL] left outer join only select newest record Appologies for not making it clearer. stock_details is simply a view of table stock, pulling in some

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Thomas Kellerer
Gary Stainburn, 23.05.2012 11:47: Here is a select to show the problem. There is one stock record and two tax records. What I'm looking for is how I can return only the second tax record, the one with the highest ud_id select s_stock_no, s_regno, s_vin, s_created, ud_id, ud_handover_date from st

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
and of the > desired output? For me it would be easier... > > Best, > Oliver > > - Original Message - > From: "Gary Stainburn" > To: > Sent: Wednesday, May 23, 2012 10:27 AM > Subject: [SQL] left outer join only select newest record > > > Hi f

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Pavel Stehule
2012/5/23 Gary Stainburn : > 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 u

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Oliveiros d'Azevedo Cristina
example of what you have and of the desired output? For me it would be easier... Best, Oliver - Original Message - From: "Gary Stainburn" To: Sent: Wednesday, May 23, 2012 10:27 AM Subject: [SQL] left outer join only select newest record Hi folks, I know I've seen

[SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
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 ob