Zviki,
One thing you can try is to use the union all clause
e.g.,
SELECT ... FROM TABLE WHERE ID=?
UNION ALL
SELECT ... FROM TABLE WHERE ID=?
UNION ALL
SELECT ... FROM TABLE WHERE ID=?
.
.
.
You can also prepare the statement and then bind parameters and
re-execute it repeatedly, which should be pretty fast if you're
running an embedded database, but will cause extra round trips in
server mode.
Which works fastest in this situation often depends on the details of
the application, so if you really want to maximize speed you'll have
to test the alternatives.
- Johann
On Mon, Feb 16, 2009 at 6:58 AM, [email protected] <[email protected]> wrote:
>
> Hi,
>
> I have a list of IDs which I need to fetch from the database. I
> currently use a query of the form:
>
> SELECT * FROM TABLE WHERE ID IN (?,?,?,?,?,....)
>
> I construct the number of parameters dynamically from Java and assign
> the IDs when executing this prepared statement.
>
> However, this technique does not maintain the order. I can, of course,
> sort the rows after fetching. However, for the sake of performance, I
> would prefer a better solution.
>
> One possible approach is to fetch each row individually. I'm not sure
> if this is better. Any help would be appreciated.
>
> Thanks,
> Zviki
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---