Re: Different type of query - Mailing list pgsql-sql

From Steve Crawford
Subject Re: Different type of query
Date
Msg-id 48502109.4090300@pinpointresearch.com
Whole thread Raw
In response to Re: Different type of query  (PostgreSQL Admin <postgres@productivitymedia.com>)
Responses Tsearch  (PostgreSQL Admin <postgres@productivitymedia.com>)
List pgsql-sql
> I would like to have multiple values nutrient_no:
> ndb_no | nutrient_no | nutrient_value
> --------+-------------+----------------
> 13473 |         203 |          24.18
> 13473 |         204 |          15.93
> 13473 |         205 |              0
> 13473 |         207 |            1.1
> 13473 |         208 |            247
> 13473 |         221 |              0
>
> I'm thinking:
> select nutrient_no, nutrient_value from nutrient_data where ndb_no = 
> 13473 and (nutrient_no = '203' or nutrient_no = '204' or nutrient_no = 
> 208);
>
Depending on what you are trying to achieve:

Particular ndb_no and multiple nutrient_no, note that output of ndb_no 
is superfluous as it is always the same:
select nutrient_no, nutrient_value from nutrient_data where ndb_no = 
13473 and nutrient_no in ('203', '204','208');

Size limited list (say top 5 nutrient values) for a given ndb_no:
select nutrient_no,nutrient_value from nutrient_data where ndb_no = 
13473 order by nutrient_value limit 5;

Cheers,
Steve



pgsql-sql by date:

Previous
From: PostgreSQL Admin
Date:
Subject: Re: Different type of query
Next
From: PostgreSQL Admin
Date:
Subject: Tsearch