Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[SQL] Order of Appearence in Query Results.

Tags:
  1. Mar 24, 2015 #1

    WWGD

    User Avatar
    Science Advisor
    Gold Member

    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 cant think of other cases at this point)?
    Thanks.
     
  2. jcsd
  3. Mar 24, 2015 #2
    Using SELECT * (which you should try to avoid) will display the fields in the order in which they were created in the table (not the index, if there is one).
     
  4. Mar 24, 2015 #3

    WWGD

    User Avatar
    Science Advisor
    Gold Member

    Thank; why should I try to avoid Select * ?
     
  5. Mar 24, 2015 #4
    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.
     
  6. Mar 28, 2015 #5
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [SQL] Order of Appearence in Query Results.
  1. I need a SQL query (Replies: 3)

  2. Need Help on SQL query (Replies: 3)

  3. SQL Help (Replies: 2)

Loading...