按原始顺序显示列名?
Display column names in their original order?
我试图在 MySQL 中一次显示一个列名称,但问题是它一直按字母顺序显示它们。我使用的语法是:
select column_name from information_schema.columns where table_schema =
'customer_info' and table_name='customer_contact' order by column_name LIMIT 1 OFFSET 0;
在customer_contact
table中有三列,分别是cust_id
、cust_cell_num
和cust_email
。当我使用上面的语法时,它显示 cust_cell_num
而不是 cust_id
。
将语法更改为以下内容时:
select column_name from information_schema.columns where table_schema =
'customer_info' and table_name='customer_contact' order by column_name LIMIT 3 OFFSET 0;
它按以下顺序显示列名称:cust_cell_number
、cust_email
、cust_id
。
如何让它按照它们在数据库中实际出现的顺序显示它们,即:cust_id
、cust_email
、cust_cell_num
?
试试这个:
select column_name
from information_schema.columns
where table_schema = 'customer_info'
and table_name = 'customer_contact'
order by ordinal_position
limit 3 offset 0;
在这里查看官方手册The INFORMATION_SCHEMA COLUMNS Table
我试图在 MySQL 中一次显示一个列名称,但问题是它一直按字母顺序显示它们。我使用的语法是:
select column_name from information_schema.columns where table_schema =
'customer_info' and table_name='customer_contact' order by column_name LIMIT 1 OFFSET 0;
在customer_contact
table中有三列,分别是cust_id
、cust_cell_num
和cust_email
。当我使用上面的语法时,它显示 cust_cell_num
而不是 cust_id
。
将语法更改为以下内容时:
select column_name from information_schema.columns where table_schema =
'customer_info' and table_name='customer_contact' order by column_name LIMIT 3 OFFSET 0;
它按以下顺序显示列名称:cust_cell_number
、cust_email
、cust_id
。
如何让它按照它们在数据库中实际出现的顺序显示它们,即:cust_id
、cust_email
、cust_cell_num
?
试试这个:
select column_name
from information_schema.columns
where table_schema = 'customer_info'
and table_name = 'customer_contact'
order by ordinal_position
limit 3 offset 0;
在这里查看官方手册The INFORMATION_SCHEMA COLUMNS Table