Link to home
Start Free TrialLog in
Avatar of pda4me
pda4me

asked on

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 ?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sure you may provide the name of the columns in the select list

Select col1, col2, col3, .... coln
from TableName
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.
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pda4me
pda4me

ASKER

Thanks!
@angelIII: very well put! ~Ray
>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 ...
Avatar of pda4me

ASKER

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!
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