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

Re: join with 1 row limit

From: Behringer Behringer <behringerdj(at)yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: join with 1 row limit
Date: 2011-01-15 18:37:54
Message-ID: 272788.28779.qm@web45203.mail.sp1.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
Sorry for that

I just want to get one row from images table for each product row from products table.

I tried using a subquery with ROW() it works but all columns are returned as a record and I don't know how to extract the data as separate columns, this is the closest I got

SELECT 
p.*,
(SELECT ROW(id,server_id,format,product_id) FROM products_images pi WHERE pi.product_id = p.id LIMIT 1) AS image

FROM products p

WHERE p.company = 7 ORDER BY id ASC LIMIT 10

--- On Sat, 1/15/11, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Subject: Re: [NOVICE] join with 1 row limit
> To: "Behringer Behringer" <behringerdj(at)yahoo(dot)com>
> Cc: pgsql-novice(at)postgresql(dot)org
> Date: Saturday, January 15, 2011, 7:49 AM
> Behringer Behringer <behringerdj(at)yahoo(dot)com>
> writes:
> > In mysql this query works fine, what is the equivalent
> in posgresql?
> > SELECT *
> > FROM 
> > products p LEFT JOIN
> > products_images pi ON p.id = pi.product_id  LIMIT
> 1
> > WHERE products.company = 7
> 
> When asking that sort of question, it would be a good idea
> to explain
> exactly what you expect that syntax to do.  Not all of
> us know every
> nook and cranny of mysql's nonstandard behaviors.
> 
>            
> regards, tom lane
> 


      

In response to

Responses

pgsql-novice by date

Next:From: Jasen BettsDate: 2011-01-16 11:17:23
Subject: Re: join with 1 row limit
Previous:From: Tom LaneDate: 2011-01-15 15:49:09
Subject: Re: join with 1 row limit

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