[英]MySQL Like statement in SELECT column_name
I am trying to select the column names from a specific table, where the table name is like '98673'我正在尝试从特定表中选择列名,其中表名类似于“98673”
So I am using this:所以我正在使用这个:
SELECT
column_name
FROM
information_schema.columns
WHERE
table_name='lime_survey_98673'
AND column_name LIKE '98673'
However this will not result in any data.但是,这不会产生任何数据。 Though I do have column names with '98673Blah' in there.
虽然我的列名中确实有“98673Blah”。
I know I must be doing something wrong, but what??我知道我一定做错了什么,但是什么?
For the LIKE you have to add a wildcard %, so:对于 LIKE,您必须添加通配符 %,因此:
SELECT
column_name
FROM
information_schema.columns
WHERE
table_name='lime_survey_98673'
AND column_name LIKE '98673%'
USE %
使用
%
SELECT column_name
FROM information_schema.columns
WHERE table_name='lime_survey_98673'
AND column_name LIKE '%98673%'
%
indicates a wildcard and returns any column_name
that contains 98673
%
表示通配符并返回任何包含98673
的column_name
Try it without the part AND column_name LIKE '98673'
unless you really need it or:除非你
AND column_name LIKE '98673'
需要它或者:
SELECT column_name
FROM information_schema.columns
WHERE table_name LIKE '%lime_survey_98673%'
-- AND column_name LIKE '%98673%' // only if needed
For more information take a look at the documentation for:有关更多信息,请查看以下文档:
You need to add %
您需要添加
%
SELECT
column_name
FROM
information_schema.columns
WHERE
table_name='lime_survey_98673'
AND column_name LIKE '%98673%'
this means that column_name
contains 98673
.这意味着
column_name
包含98673
。
也可以这样做:
show columns from lime_survey_98673 like '%98673%';
I think you need to add wildcard with table name also.我认为您还需要添加带有表名的通配符。
SELECT
column_name,
table_name
FROM
information_schema.columns
WHERE
schema_name = 'db_name'
AND table_name='%98673%'
AND column_name LIKE '%98673%'
In this way you can get columns name list all tables and there columns name contain the text like '98673' from specific database or schema.通过这种方式,您可以获得列名列出所有表,并且列名包含来自特定数据库或模式的“98673”等文本。
使用这个查询
SHOW COLUMNS FROM `table_name` LIKE 'coloums_name';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.