It would be convenient for me to get a list of those fields ordered by
field / column name.

SELECT *
FROM information_schema.columns
WHERE table_schema='db' AND table_name='tbl';

PB

-----

Ricardo Dias Marques wrote:
Hi all,

I have a Linux server with MySQL 5.0 (5.0.67) installed.

In that server, I have a database that has a table with many fields (around 60).

It would be convenient for me to get a list of those fields ordered by
field / column name. Unfortunately, a "DESC tablename ("DESCRIBE
tablename") command, in "MySQL monitor" (the MySQL command line
client) returns a table with that table fields, but the fields appear
in a strange order. I'm guessing this strange order can be the order
given by the "CREATE TABLE" command that was used to create that
table.

The first thing I tried was to write "DESC tablename ORDER BY Field".
That failed:

ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'ORDER BY Field' at line 1


So, I went to read the online documentation about the DESCRIBE command
and the SHOW COLUMNS (or its synonym SHOW FIELDS) command:

MySQL :: MySQL 5.0 Reference Manual :: 12.3.1 DESCRIBE Syntax
http://dev.mysql.com/doc/refman/5.0/en/describe.html

MySQL :: MySQL 5.0 Reference Manual :: 12.5.5.5 SHOW COLUMNS Syntax
http://dev.mysql.com/doc/refman/5.0/en/show-columns.html


Unfortunately, I'm NOT finding, in those 2 web pages, any hints about
sorting the list of fields by any criteria.

I did some "google" searches about this, but I didn't find any
relevant results (maybe I'm using the wrong keywords for my searches).

So, I'm asking this: does anyone know a MySQL command to get this list
of fields sorted by field name? Or do you achieve this result by other
means (e.g: using some GUI tool, copying the list of fields to a text
file and sorting it, writing some script...)?


Thanks in advance!

Best wishes,
Ricardo Dias Marques
lists AT ricmarques DOT net

------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.432 / Virus Database: 270.14.138/2618 - Release Date: 01/13/10 07:35:00

Reply via email to