Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is faster: "SELECT * FROM table" or "SELECT x,y,q FROM table" (from a table with 4 fields)

I'm wondering, what is fastest (or lightest for the database to handle)

Let's say, the db table has 4 fields: x,y,z,q

I only need 3: x,y,q

What way is fastest/easiest for the database to perform (using PHP).. "SELECT * FROM table" or "SELECT x,y,q FROM table"?

Would the same apply if the table had 5 or more fields while I still only needed to select 3?

like image 349
mowgli Avatar asked May 09 '12 14:05

mowgli


2 Answers

SELECT x,y,z FROM table is faster because MySQL won't have to look up what columns are in your table before executing the query.

like image 65
John Conde Avatar answered Sep 27 '22 22:09

John Conde


In most databases the * is slower than specifying the fields.

It's also a good programming practice to put all the columns, even though they are many.

like image 34
Julio Avatar answered Sep 27 '22 22:09

Julio