Results 1 to 3 of 3

Thread: [Resolved] SQL: SELECT * FROM question

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    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.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width