List:General Discussion« Previous MessageNext Message »
From:Roger Baklund Date:January 18 2005 12:58pm
Subject:Re: SHOW COLUMNS Syntax Using 3.23.54 Please!
View as plain text  
shaun thornburgh wrote:
> I am trying to get all field names from my table that begin with
> letter X or Y, however the following statement and many variations I
> have tried produce an error:
> 
> SHOW COLUMNS FROM TABLE LIKE "X%" OR LIKE "Y%"

According to the manual, the pattern for SHOW COLUMNS is:

   SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE 'pattern']

There is no WHERE clause or expression evaluation here, to achieve what 
you want you must issue the statement twice:

SHOW COLUMNS FROM tbl_name LIKE "X%";
SHOW COLUMNS FROM tbl_name LIKE "Y%";

<URL: http://dev.mysql.com/doc/mysql/en/SHOW_COLUMNS.html >

You didn't ask, but a shorter way to write this is using the DESCRIBE 
command, which can be abbreviated to DESC:

DESC tbl_name "X%";
DESC tbl_name "Y%";

<URL: http://dev.mysql.com/doc/mysql/en/DESCRIBE.html >

-- 
Roger

Thread
SHOW COLUMNS Syntax Using 3.23.54 Please!shaun thornburgh18 Jan
  • Re: SHOW COLUMNS Syntax Using 3.23.54 Please!Roger Baklund18 Jan