MySQL select/insert/update, does column order matt

2019-06-09 21:05发布

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条回答
女痞
2楼-- · 2019-06-09 21:40

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?

查看更多
登录 后发表回答