Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

mysql WRONGLY return column names of a table alphabetically

ok i’m talking about mysql 8 dbms;
i have a table named users.
below query would return a result set and order of columns are right[i.e in order in which i define columns of this table].

select * from users

but the problem is this one:

SELECT COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'users';

when i execute this, mysql client return column names in alphabetical order which is wrong and i don’t have any idea why this is happening.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

anybody has any idea why this is happening?

ok i need add more details; guys the second query is not in my hand and actually is used by laravel; getColumnListing() defined in Builder class also return column names in the wrong order and after that i use my mysql-client to check ordering and use that sql-stmt; so i guess laravel-method mentioned are doing that wrongly in a way but nobody complains so i thought then maybe my mysql config is wrong.

>Solution :

This is not wrong. The rows in SQL tables are not ordered in any way, even in the information schema. If you have not provided an ORDER BY clause, the server is free to return whatever order is convenient.

You need ORDER BY ordinal_position.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading