- Feb 4, 2003
- 3,370
- 0
- 71
Say my database has two tables, accounts and transactions. Every transaction is associated with a certain account, account_id being the foreign key.
Lets say an application which is integrated with this database wants to retrieve one account and all it's transactions. One way would be
SELECT * FROM accounts WHERE account_id=123
SELECT * FROM transactions WHERE account_id=123
This could be slow if the tables are large since it has to search through the entire transactions table to find all the transactions with that id. In a regular programming language however, this is fast, because the account object would have a pointer to an array of all it's transaction objects.
Is there any standard SQL way to implement such a pointer, so that once we find the account row, we have pointers to the corresponding rows in the transactions table?
Lets say an application which is integrated with this database wants to retrieve one account and all it's transactions. One way would be
SELECT * FROM accounts WHERE account_id=123
SELECT * FROM transactions WHERE account_id=123
This could be slow if the tables are large since it has to search through the entire transactions table to find all the transactions with that id. In a regular programming language however, this is fast, because the account object would have a pointer to an array of all it's transaction objects.
Is there any standard SQL way to implement such a pointer, so that once we find the account row, we have pointers to the corresponding rows in the transactions table?