Search code examples
mysqlsqlselectinformation-schema

How to find the similar column names from a database table?


How do i find similar column names from a database table?

for e.g.

a database table

1_1  1_2  1_3  5_6  67
    |    |    |    |   
    |    |    |    |

So, 1_1, 1_2, 1_3, 5_6 and 67 are the column names of a database table. And i would like to retrieve only the column names starts with 1 (1_1, 1_2 and 1_3). i tried the sql query but it dint work..

SELECT 1 LIKE '%1%' FROM sheet1;

It shows something of this short

1 LIKE '%1%'
         1
         1

Solution

  • Documentation find here

    SHOW COLUMNS FROM tbl_name FROM db_name
    LIKE '1%'
    

    To get the contents of the respective column:

    SQL Fiddle