In general, which is more expensive? A double-nested for loop and one call to a database or a call to a database for each of N items in only one for loop?
Not looki
In general, the fewer times you hit the database, the better. There are a number of reasons for this, including: