0

I run the simplest query:

select id from table_xx where name='aaa'

toward this table: table_xx

-----------------------------
|      id       |    name    |
-----------------------------
|      1        |    aaa     |
|      2        |    bbb     |
|      3        |    aaa     |
------------------------------

Note: id is a primary key.

so if I run code like this:

result = execute_query(query)
print (result[0][0])         

Will it ALWAYS return the smallest id first in dataset? which is id=1

or is there a chance that id=3 will be returned as the first row in dataset

Mr.Cocococo
  • 1,401
  • 2
  • 11
  • 13

2 Answers2

1

There is no "default order". You will only get a specific sort order if you use order by.

If there is no order by, the database is free to return the rows in any order it thinks is most efficient.

P.S. original detailed answer

AlexElizard
  • 785
  • 4
  • 17
0

Adding a sort clause to your sql query would guarantee this