0

I'm just wondering when you do a query and you use ORDER BY should the fields you use in the ORDER BY clause always be included in the SELECT list even if you don't need them? Is this beneficial in some way?

1
  • 2
    It's completely down to your individual requirements. Do you need the column? Yes/No.
    – Philᵀᴹ
    Jul 6, 2016 at 10:53

1 Answer 1

4

There is no benefit to including the ORDER BY columns in the SELECT list. On the contrary, having unrequired columns in the SELECT list incurs a fractional overhead in run time and a larger one in maintenance.

2
  • Ok thanks. I was thinking by including the data in the result set it lessened the work MySQL needed to do to get the data to know how to sort the results.
    – Brett
    Jul 6, 2016 at 11:20
  • 3
    @Brett the query needs to read all the columns used, no matter the clause. The SELECT clause only specifies which columns will be sent to the client.
    – jkavalik
    Jul 6, 2016 at 20:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.