Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: Different t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 3523 of 3799
Post > Topic >>

Re: Different type of query

by mailing_lists@[EMAIL PROTECTED] (Mark Roberts) Jun 11, 2008 at 11:56 AM

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


-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 2 Posts in Topic:
Re: Different type of query
mailing_lists@[EMAIL PROT  2008-06-11 11:56:12 
Re: Different type of query
postgres@[EMAIL PROTECTED  2008-06-11 15:00:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:36:14 CST 2008.