I have a question about SHOW COLUMNS FROM table like \'column name\'\"
.
I have already tried some tests for some times, it seems be similar like \"where colu
It's more like
WHERE column_name LIKE 'column name'
Since it uses LIKE
, you can put wildcard patterns in the parameter, e.g.
SHOW COLUMNS FROM table LIKE '%id'
will find all columns that end in id
.
If there are no wildcard characters, then LIKE
is equivalent to =
.
If you don't want to use LIKE
, you can use WHERE
:
SHOW COLUMNS FROM table WHERE field = 'column name';
In the SHOW COLUMNS
output, the field
column contains the column names. The WHERE
clause also permits testing other attributes, e.g.
SHOW COLUMNS FROM table WHERE type LIKE 'varchar%'
will find all VARCHAR
columns.
maybe this: SHOW COLUMNS FROM accounts LIKE'id'
Where is used to get an exact match where as like is used to get a wider range of columns using wildcards.
SHOW COLUMNS FROM table like 'my%";
The above will find all columns that begin with my.
Where as with a where clause you cannot use wildcards and will only get returned exact matches.
Obviously you could use where with between
,>
or <
etc in other cases which would give you a wider range but still not allow you to use any wildcards.
SHOW ... LIKE behaves like the use of the LIKE operator in the WHERE
clause of a common query:
SHOW COLUMNS Syntax
SHOW [FULL] COLUMNS {FROM | IN} tbl_name [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]
SHOW COLUMNS displays information about the columns in a given table. It also works for views. The LIKE clause, if present, indicates which column names to match. The WHERE clause can be given to select rows using more general conditions, as discussed in Section 21.32, “Extensions to SHOW Statements”.
Emphasis by me.