which one is faster (php-mysql command)

Discussion in 'PHP' started by dracula51, Nov 12, 2009.

  1. #1
    number 1
    SELECT * FROM table1 WHERE id=1 ORDER BY name
    PHP:

    number 1
    SELECT `name`,`country` FROM table1 WHERE id=1 ORDER BY name
    PHP:

    in that table, there r 12 rows. but in a page i need just two of them.
    im curious which one i shud use....i mean, is number2 command save some server resource & faster ?? or there's not much difference
     
    dracula51, Nov 12, 2009 IP
  2. KiruSoft

    KiruSoft Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    this one SELECT `name`,`country` FROM table1 WHERE id=1 ORDER BY name
     
    KiruSoft, Nov 12, 2009 IP
  3. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #3
    offcourse SELECT `name`,`country` FROM table1 WHERE id=1 ORDER BY name
     
    Bohra, Nov 12, 2009 IP
  4. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #4
    You should also always use LIMIT 1 if you´re just searching for 1 row.. then it will stop searching on first match.. else it will search entire table even if it has the match you were searching for :)
     
    n3r0x, Nov 12, 2009 IP