|
which server are you trying to tax less, the database server, or the web servers(s)? or are they the same machine?
it is usually a better idea to minimize the number sql queries. these may have a very high latency if your database is under high load. in a traditional web setup, you have several front facing web machines all accessing one database. the database very often becomes the bottleneck, whereas the webservers usually have ram and cpu time to spare. a query that returns all the data at once only requires one-time processing by the db engine, whereas a thousand small queries that return the data individually require the db to do the same amount of work for each one. it is rarely the case where doing the multiple queries is a good idea.
if the amount of data you're selecting is really large, though (tens of thousands of rows or more), you may want to look at more efficient ways of handling this query, or partitioning the result set. otherwise your webserver will be spending alot of needless time copying memory around, and may even exceed the script memory limit (or timeout).
oh, your method 2 sql statement should probably be "select *"
|