Re: Different type of query

From: PostgreSQL Admin <postgres(at)productivitymedia(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Different type of query
Date: 2008-06-11 18:41:48
Message-ID: 48501C6C.3010906@productivitymedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Steve Crawford wrote:
> PostgreSQL Admin wrote:
>> I have a table ...
>>
>> when I run this query:
>> select ndb_no, nutrient_no, nutrient_value from nutrient_data where
>> ndb_no = 13473;
>>
>> it produces:
>> ndb_no | nutrient_no | nutrient_value
>> --------+-------------+----------------
>> 13473 | 203 | 24.18
>> ...
>>
>>
>> I want only certain nutrient_no (say 8 of them) and the nutrient
>> values by ndb_no.
> Not entirely sure I understand the question. Do you mean that for a
> given nutrient_no, you want the complete list of nutrient values? If
> so, it's just:
>
> --Example for nutrient_no 203:
> SELECT ndb_no, nutrient_value from nutrient_data where nutrient_no=203;
>
> Cheers,
> Steve
>
>
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);

Now is that the most efficient SQL query?

Thanks,
J

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mark Roberts 2008-06-11 18:56:12 Re: Different type of query
Previous Message Steve Crawford 2008-06-11 18:27:36 Re: Different type of query