|
-
Jan 17th, 2004, 12:58 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] SQL: SELECT * FROM question
What's the difference in speed and memory between doing:
Code:
SELECT * FROM tblNames WHERE something='value'
and:
Code:
SELECT phoneNumber FROM tblNames WHERE something='value'
Is the second method any faster? I suppose it saves up on memory because it isn't returning as much stuff as the first example.
Is it more efficient to go with the second one?
Last edited by The Hobo; Jan 17th, 2004 at 03:01 PM.
-
Jan 17th, 2004, 02:38 PM
#2
When you do a "SELECT *" you are selecting every field and its corresponding value, within the constraints of your condition.. When you specifically select one field, you get a faster response and save on memory. If you have a huge database, it's going to matter whether or not you use 'SELECT *' or 'SELECT fieldname'.
When you're querying, I've been told to only query what you want.. so, if you want fieldname, then "SELECT fieldname", and if you want field1 and field2, then "SELECT field1, field2", etc. I also suppose that if you're querying and requesting 4 fields out of a table that only has 5 or 6 fields, it wouldn't do much harm with a "SELECT *" because you're saving some code space, well, unless you're selecting 400 different rows or something..
so, to answer your question in a summary.. The second method is faster, and it is more efficient to go with the second method.
-
Jan 17th, 2004, 03:01 PM
#3
Thread Starter
Stuck in the 80s
Thanks. I knew what each did, but I wasn't sure if the second was actually faster. I guess I go through my application and do some replacing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|