- 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
How to display the column names from a table excluding some in MySQL?
To exclude some of the column names, use NOT IN.
Let us first create a table −
mysql> create table DemoTable780 ( CustomerId int, CustomerName varchar(100), CustomerAge int, CustomerCountryName varchar(100), isMarried tinyint(1) ); Query OK, 0 rows affected (0.47 sec)
Here is the query to exclude result −
mysql> select group_concat(column_name) from `information_schema`.`COLUMNS` m where table_schema = 'web' and table_name = 'DemoTable780' and column_name not in ('CustomerId','CustomerCountryName') group by table_schema,table_name;
This will produce the following output -
+------------------------------------+ | group_concat(column_name) | +------------------------------------+ | CustomerName,CustomerAge,isMarried | +------------------------------------+ 1 row in set (0.01 sec)
Advertisements