• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Order of records in a table?

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

Suppose i have a table "Employee".
I insert Employee1 into Employee table.
Then I insert Employee2 into Employee table.
Now if i do "Select * from Employee", will i always get Employee1 followed by Employee2. In other words will the order be always Employee1 and then Employee2. Is there any change that i may get Employee2 and then Employee1?

Regards,
Saj
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The order in which you get results from a SQL database is not defined - it can change from request to request. If you want the same order every time you'll have to explicitly sort the results.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can specify: ORDER BY Employee Desc

This will take the results and display them based upon the Employee column in descending order, basically showing it Employee2, Employee1. You can also play with the GROUP BY function to group results together, such as all employees in a particular work center. You can even use the ORDER BY with the GROUP BY to make the results return exactly like you want them to.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic