From: | Mark Roberts <mailing_lists(at)pandapocket(dot)com> |
---|---|
To: | PostgreSQL Admin <postgres(at)productivitymedia(dot)com> |
Cc: | Steve Crawford <scrawford(at)pinpointresearch(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Different type of query |
Date: | 2008-06-11 18:56:12 |
Message-ID: | 1213210572.9666.98.camel@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 2008-06-11 at 14:41 -0400, PostgreSQL Admin wrote:
> 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
It seems that you'd want to do something like:
select nutrient_no, nutrient_value from nutrient_data where ndb_no =
13473 and nutrient_no in (203, 204, 208..)
You could also grab the most significant 8 nutrients by doing something
like:
select nutrient_no, nutrient_value from nutrient_data where ndb_no =
13473 order by nutrient_value desc limit 8
-Mark
From | Date | Subject | |
---|---|---|---|
Next Message | PostgreSQL Admin | 2008-06-11 19:00:28 | Re: Different type of query |
Previous Message | PostgreSQL Admin | 2008-06-11 18:41:48 | Re: Different type of query |