including limited lines depending on input parameter
including limited lines depending on input parameter
Hello all,
Okay, this is me back again regarding those two tables I needed
to join again, and . Once these tables are joined together
the resulting table has two fields of interest, and . There
can be multiple
values for one value. I have an input parame-
ter that can have three values, 1, 2, or 3+. Based on I need
to include in the output table either one
value for each va-
lue (as far as I know chosen at random) if one exists, two
values
for each value (again chosen at random) if two exist, or all
values for each value, respectively.
Does anyone know how I would go about generating such an output
table?
I have a book _Practical PostgreSQL_ that I thought would help me
figure out how to do this (since my SQL server is PostgreSQL), but so
far it has been no use. Any information on this would be greatly ap-
preciated.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
Re: including limited lines depending on input parameter
On Apr 27, 2007, at 11:10 AM, kvnsmnsn@cs.byu.edu wrote: > Okay, this is me back again regarding those two tables I needed > to join again, and . Once these tables are joined together > the resulting table has two fields of interest, and. There > can be multiple
values for one value. I have an input parame- > ter that can have three values, 1, 2, or 3+. Based on I need > to include in the output table either one
value for each va- > lue (as far as I know chosen at random) if one exists, two
values > for each value (again chosen at random) if two exist, or all
> values for each value, respectively. > > Does anyone know how I would go about generating such an output > table? > > I have a book _Practical PostgreSQL_ that I thought would help me > figure out how to do this (since my SQL server is PostgreSQL), but so > far it has been no use. Any information on this would be greatly ap- > preciated. You'll want to use the LIMIT clause, though in the 3+ case you'll want to have no LIMIT. You should probably wrap all this in a plpgsql function. -- Jim Nasby jim@nasby.net EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)