- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Select column names containing a string in MySQL?
For this, you can use SHOW COLUMNS command. Following is the syntax. Here, we have set the string using LIKE −
SHOW COLUMNS FROM yourTableName LIKE ‘yourStringValue’;
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.69 sec)
Here is the query to select column names containing a specific string −
mysql> SHOW COLUMNS FROM DemoTable LIKE 'FirstName';
Output
+-----------+-------------+------+-----+----------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+----------+-------+ | FirstName | varchar(20) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 1 row in set (0.05 sec)
Advertisements