2016-08-02 90 views
0

我试图在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表有三列这是cust_idcust_cell_numcust_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_numbercust_emailcust_id

我怎样才能让它按照它们实际出现在数据库上的顺序显示它们:cust_idcust_emailcust_cell_num

回答

4

试试这个:

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

+0

谢谢你,成功了! :d – Osiris93