Re: [SQL] Understanding Binary Data Type

2012-05-23 Thread Jasen Betts
On 2012-05-22, Carlos Mennens wrote: > Hello everyone! I wanted to ask the list a question about the 'bytea' > data type & how I can picture this in my head. I've been reading SQL > for about a few months now and since then, I've only been working with > textual data. Basically I'm familiar with s

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] master/detail

2012-05-23 Thread Andreas Kretschmer
Jan Bakuwel hat am 21. Mai 2012 um 01:17 geschrieben: > Hi, > > I'm trying to get my head around the following question. As an example > take a table with products: > > productid (pk) > name > > and productprice > > productpriceid (pk) > productid (fk) > pricedate > price > > There are multipl

Re: [SQL] sub query and AS

2012-05-23 Thread Lee Hachadoorian
On Wed, May 23, 2012 at 5:24 AM, Ferruccio Zamuner wrote: > Hi, > > I like PostgreSQL for many reasons, one of them is the possibility to use > sub query everywhere. Now I've found where it doesn't support them. > > I would like to use a AS (sub query) form. > > This is an example: > > First the s

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

2012-05-23 Thread Oliveiros d'Azevedo Cristina
Sorry, Gary, I made a mistake on the last column. It should be SELECT subq.s_stock_no,subq.s_regno,subq.s_vin,subq.s_created,subq.m, sec.ud_handover_date FROM (select s_stock_no, s_regno, s_vin, s_created, MAX(ud_id) as m from stock s left outer join used_diary u on s.s_regno = u.ud_pex_regis

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

2012-05-23 Thread Oliveiros d'Azevedo Cristina
Hello again, Gary, I don't know if this query works OK, i havent tried it. But, If I understood correctly this can be one way to do what you want. Could you please tell me if it worked and if it didn't why, so we can tweak it. Best, Oliver SELECT subq.s_stock_no,subq.s_regno,subq.s_vin,subq

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
Appologies for not making it clearer. stock_details is simply a view of table stock, pulling in some lookup values. used_diary is the name of the table containing the tax requests. It's called the used_diary because it was the diary for taxing used vehicles. Here is a select to show the proble

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
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 ex

[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

[SQL] sub query and AS

2012-05-23 Thread Ferruccio Zamuner
Hi, I like PostgreSQL for many reasons, one of them is the possibility to use sub query everywhere. Now I've found where it doesn't support them. I would like to use a AS (sub query) form. This is an example: First the subquery: select substr(descr, 7, length(descr)-8) from (select string