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

Re: Sort of Complex Query - Howto Eliminate Repeating Results

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: operationsengineer1(at)yahoo(dot)com
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Sort of Complex Query - Howto Eliminate Repeating Results
Date: 2006-01-12 20:35:32
Message-ID: 20060112203531.GA22845@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Thu, Jan 12, 2006 at 12:07:12PM -0800, operationsengineer1(at)yahoo(dot)com wrote:
> SELECT DISTINCT t_product.product_id,
>        t_product.product_number,
>        t_serial_number.serial_number_id,
>        t_serial_number.serial_number
[...]
> ORDER BY t_serial_number.serial_number::int ASC
> 
> resulting error:
> 
> ERROR:  for SELECT DISTINCT, ORDER BY expressions must
> appear in select list

What data type is serial_number?  I'm guessing not integer, else
you wouldn't be casting it to integer in the ORDER BY clause.  If
you need that cast then also use it in the SELECT list:

SELECT DISTINCT t_product.product_id,
       t_product.product_number,
       t_serial_number.serial_number_id,
       t_serial_number.serial_number::int

-- 
Michael Fuhr

In response to

Responses

pgsql-novice by date

Next:From: operationsengineer1Date: 2006-01-12 20:57:30
Subject: Re: Sort of Complex Query - Howto Eliminate Repeating Results
Previous:From: tmorelliDate: 2006-01-12 20:19:49
Subject: Re: A question about pages. Now is VERY clear!

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