|Subject||Re: [firebird-support] Selecting arbitrary records in an arbitrary order|
|Author||Walter R. Ojeda Valiente|
On Wed, Nov 19, 2014 at 5:50 PM, Caroline Beltran caroline.d.beltran@... [firebird-support] <email@example.com> wrote:
I hope that someone can advise how I can efficiently arbitrarily select data from a table. I am provided with a list of IDs to display, for example:
Employee ID Numbers: 1032, 624, and 2841.
This would be the output (in the same order as the list above):
Employee ID FName LName
------------------ --------- ----------
1032 Frank Burns
624 Jill Applegate
2841 Angie Cullens
The easiest and most obvious way to get this output is by using the SELECT statement 3 times:
SELECT id, fname, lname FROM employees WHERE id = 1032
SELECT id, fname, lname FROM employees WHERE id = 624
SELECT id, fname, lname FROM employees WHERE id = 2841
Please keep in mind that there is no criteria other than the ID and order provided in the list above.
Although this works, I would like to find the most efficient way to do this. My first though was to create a temporary table where I insert the 3 IDs and link them to the Employees table but that looks even less efficient.
What came to mind next was a STORED PROCEDURE.
What I would like to know is if it is possible to pass a variable amount of IDs and have the procedure parse each id and return the output as shown above?
If so, would this be the most efficient way to have Firebird fulfill this requirement?