1

i will get straight to the point and i hope my question is understandable because my english is not very well. So, i use mysql 8.0.23 and i have table like this

Field Type Null Key Default Extra
id_mhs int NO PRI NULL auto_increment
nama varchar(45) YES NULL
npm char(8) YES UNI NULL
j_kelamin enum('L','P') YES NULL
t_lahir date YES NULL
alamat varchar(50) YES NULL
kota varchar(45) YES NULL
telepon varchar(12) YES UNI NULL
email varchar(50) YES UNI NULL

And i showed the data like this

id_mhs nama npm
1 AA Aditya A 51411136
2 A Aditya A 51412371
3 A Dimas A 51411111
4 A Faisal Dimas 51411112
5 A Faridah Nur 51411113

The result was right but when i tried this query mysql> select id_mhs, npm from mahasiswa limit 10;

id_mhs npm
28 51411036
47 51411054
83 51411100
84 51411101
85 51411102

The result was sorted by npm not with id_mhs, same result when i use order by npm, then i tried to remove unique constraint in column npm and the data sorted with id_mhs. So, column with unique constraint & string data type will prioritized to sort data than primary key?

1 Answers1

0

There is no 'default' order in a sql table, you have to use ORDER BY to order what you want.

Good way is to have, as you do have, an unique id as unique index (primary key is nice) to retrieve your 'default' order, but you have to sepcify by 'ORDER BY id'

Dri372
  • 1,275
  • 3
  • 13