Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column names from MySQL table in the right order

I am using the following SQL command to get all column names from my table in MySQL:

SELECT column_name FROM information_schema.columns where table_name = 'сведения о фильме' and table_schema = 'videokassety2';

It give me all column names in the table 'сведения о фильме', however it sorts the results and gives me the following:

ID Компании
Год выпуска
Название фильма
Номер фильма
Основные исполнители
Характер фильма

However, I do not need sorting, I need the order in which they appear in the table itself, like the following:

enter image description here

How can I get a list of column_nmaes without any sorting?

Thank you

like image 618
Al_Pacino Avatar asked Oct 22 '25 07:10

Al_Pacino


1 Answers

The column ordinal_position has the original column ordering information:

SELECT column_name
FROM information_schema.columns 
WHERE table_name = 'сведения о фильме' AND table_schema = 'videokassety2'
ORDER BY ordinal_position;
like image 80
Gordon Linoff Avatar answered Oct 23 '25 22:10

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!