Database query from Calc

I have a database created in Base and a Calc spreadsheet. For a given value in the spreadsheet I want the entry with the corresponding ID from a table in the database.

Let’s say I have a value of 42 in the spreadsheet and I want to get field ‘foo’ from a table in the db from the entry with index number 42. Is there a way to do that?

Not sure if there is any direct way to do this with Calc, but almost sure that yo can do that with macros. You will need to right some code that connects to the Base database and on change of that cell in Calc it will look up for the ‘foo’ from Base. Here is a link with description of similar question as yours.