0

If I have mySQL table with 10 fields and I only need the to retrieve values of the some fields, is it advisable to use

SELECT field1, field2, field3 FROM...

rather than

SELECT * FROM...

I mean does it help retrieval / script execution faster if Im using [SELECT field1, field2, field3....]

Paul Sanchez
  • 2,391
  • 2
  • 15
  • 9

4 Answers4

0

Yes, if you only want a small selection of fields in a table, it is better to select them rather than pull all the fields back. The difference is not huge but aiming for every optimisation, it may help.

If you have a table with 20 or so fields and want 18 of them, that is where it might be easier/neater to just do a * to get them all.

EDIT

Further information can be found on this question.

Community
  • 1
  • 1
Turnerj
  • 4,258
  • 5
  • 35
  • 52
0

yes, you should query only those fields that you need, as not needed fields will have take up network resourse(transporting from db server to backend server) and memory.

Ratna
  • 2,289
  • 3
  • 26
  • 50
0

Yes, you should always use the SELECT field1, field2, field3... form according to some.

The * is ambiguous and I see the point that just automatically selecting every column from a table is lazy although I'm guilty of using it regularly.

From an optimisation point-of-view you should select only the fields you are planning to use also. It may make debugging clearer if you know explicitly what data is being retrieved.

alvinc
  • 385
  • 3
  • 10
0

If You Query a table with 6800 records having 23 Columns

With * it took Average 0.0009 Sec in returning records

And same Query with 5 Columns took average 0.0005 Sec

Tested on Dual Core Machine 2GB RAM , Windows 7 and Phpmyadmin

Conclusion

It's always recommended to use required fields despite of * where speed is on priority

Community
  • 1
  • 1