[SQL] Order of Appearence in Query Results.

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Database Sql
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
Messages
7,828
Reaction score
13,156
Hi All, I know that if we use Select * , then the fields in the table will appear in the same order as listed. Same if we list all the fields manually, as in Select field1, field2,.., fieldn . Is it true that the order of the fields is preserved always (I can't think of other cases at this point)?
Thanks.
 
Physics news on Phys.org
WWGD said:
Thank; why should I try to avoid Select * ?
Less control and usually much less efficient. Grab only what you will use and name it. When looking through old code it's also easier to understand what you are trying to do.
 
I can't find a link right now, but remember reading somewhere - I think it was about the Codd Relational Algebra behind relational db's - that you are to think of the column names as a set not an array. In terms of writing code, the database API will almost always give you a way to get content from the db by column name not number, and its generally good form (for readability) to do so.