PHP SQL Syntax with MySQL question

I have a table with close to 100 columns that I am currently doing a select * on.

Is it better to only select the columns I need?

Instead of the SELECT * how do I name individual column in the the query?  SELECT columna, columnb, columnc ?
pda4meAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
Instead of the SELECT * how do I name individual column in the the query?  SELECT columna, columnb, columnc ?

Yes, exactly.  Performance will improve, too!

Best, ~Ray
0
 
tigin44Commented:
Sure you may provide the name of the columns in the select list

Select col1, col2, col3, .... coln
from TableName
0
 
Cornelia YoderArtistCommented:
It is definitely more efficient to select only those columns you are going to use.

If you doubt, you can set up a quick benchmark recording the time before and after queries, and see how much better.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
the explaination is mainly in the amount of data that has to be kept in the buffers on the server side, then to be transported over the network, then stored in the buffers on the client side, and finally having an array/structure for 100 items while the application only needs 3-4 of them, but has to get through all the items eventually.

it's like you would buy an entire library, just to get 3-4 books you want to read.
0
 
pda4meAuthor Commented:
Thanks!
0
 
Ray PaseurCommented:
@angelIII: very well put! ~Ray
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>it's like you would buy an entire library, just to get 3-4 books you want to read.
additionally, developers doing this kind of code (select *) are then the ones complaining about network being slow and the like :/

glad to be of assistance ...
0
 
pda4meAuthor Commented:
Yep, I just changed the select * to just the few columns I needed and its an AMAZING difference...this sure beats the cost of the upgraded server the sales rep was trying to "upgrade" us to...ha!
0
 
Ray PaseurCommented:
Bet you paid for your EE membership right there!

If you're looking for even more speed, you can try making those selection fields into indexes.

Warm regards, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.