Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

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.

I know I must be doing something wrong, but what??

like image 440
BonifatiusK Avatar asked Mar 27 '13 11:03

BonifatiusK


Video Answer


2 Answers

For the LIKE you have to add a wildcard %, so:

SELECT 
    column_name
FROM 
    information_schema.columns
WHERE 
    table_name='lime_survey_98673'
    AND column_name LIKE '98673%'
like image 119
Jester Avatar answered Oct 22 '22 07:10

Jester


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

like image 22
Darren Avatar answered Oct 22 '22 07:10

Darren