MySQL select/insert/update, does column order matt

2019-06-09 21:06发布

问题:

In my mysql db I have the fields id, name, email, age, city, phone. In that order

Does the order in which I select/insert/update these matter, in terms of speed/other?

If I say

SELECT phone, city, name, id, age, email FROM tablename
// mixed up order

As opposed to

SELECT id, name, email, age, city, phone FROM tablename
// original order of columns

EDIT: not only for one small simple query (just an example). Concern is also for 100.000 rows and multiple/advanced queries and loops

回答1:

No, it doesn't matter what order you select from. To increase speed to you can use indexes or only select the columns you actually need. When selecting, they would be returned in the order you select. You can also use GROUP BY to group the result by a particular column.

"That won't make any difference.

However, omitting columns from the SELECT clause will make it run faster since it'll send less data over the network."

Source: Does the order of columns in a select statement affect query speed?