कुछ कॉलम नामों को छोड़ने के लिए NOT IN का उपयोग करें।
आइए पहले एक टेबल बनाते हैं:
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)
कुछ कॉलम नामों को छोड़कर परिणाम प्राप्त करने की क्वेरी
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;
यह निम्नलिखिक आउटपुट देगा:
+------------------------------------+ | group_concat(column_name) | +------------------------------------+ | CustomerName,CustomerAge,isMarried | +------------------------------------+ 1 row in set (0.01 sec)
व्याख्या
INFORMATION_SCHEMA.COLUMNSमेटाडेटा टेबल में सभी कॉलम की जानकारी होती हैTABLE_SCHEMAडेटाबेस नाम है (यहां 'web')NOT IN ('CustomerId','CustomerCountryName')इन दो कॉलम को बाहर करता हैGROUP_CONCATशेष कॉलम नामों को कॉमा-सेपरेटेड सूची में जोड़ता हैGROUP BY table_schema, table_nameप्रत्येक टेबल के लिए एक पंक्ति सुनिश्चित करता है
व्यावहारिक उपयोग
यह डायनामिक SQL जनरेट करने, SELECT * से कुछ कॉलम बाहर करने, या स्क्रिप्ट में कॉलम सूची बनाने के लिए उपयोगी है।