Radhwen
Radhwen

Reputation: 232

Database entries not shown in the expected order

I have the following table structure in my Sybase database : myTable {myId1 ID, myId2 ID, myString String}

The primary Key is myId1, and I have two indexes index1 {myTable.myId1} ASC and index2 {myTable.myId2} ASC

My table contain three entries : (1,8,'first line'), (2,8,'second line') & (3,8,'third line').

Why when I execute

select * 
from myTable`

I get

3,8,'third line'
1,8,'first line'
2,8,'second line'

instead of

1,8,'first line'
2,8,'second line'
3,8,'third line'

FYI : select * from myTable order by myId1 ASC returns the wanted output.

Update : Since the result of select * from myTable is random, then why I'm always getting that exact same order each time I execute the query ?

Upvotes: 0

Views: 159

Answers (2)

AGR
AGR

Reputation: 351

You should consider data within a tables as a set which is not sorted.

Upvotes: 2

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

no database is return values in any order except you explicitly use order by for ordering it

like order by column asc or desc

as a result select * from myTable order by myId1 ASC it returns ordered data because you explicitly called it in ascending order

and the 1st query select * from myTable does not return ordered because here you didn't use any explicit ordering

Upvotes: 1

Related Questions