सबसे पहले, आपको यह जानना होगा कि टेबल में कितने कॉलम मौजूद हैं। कॉलम नाम जानने का सिंटैक्स:
show columns from yourTableName;
सभी कॉलम कॉनकैटनेट करने का सिंटैक्स:
select concat(yourColumnName1,yourColumnName2,yourColumnName3,........N) from yourTableName;
आइए पहले एक टेबल बनाते हैं:
mysql> create table DemoTable ( CustomerId int, CustomerName varchar(20), CustomerAge int ); Query OK, 0 rows affected (0.66 sec)
सटीक कॉलम जानने का क्वेरी:
mysql> show columns from DemoTable;
इससे निम्न आउटपुट प्राप्त होगा:
+--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | CustomerId | int(11) | YES | | NULL | | | CustomerName | varchar(20) | YES | | NULL | | | CustomerAge | int(11) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
इन्सर्ट कमांड का उपयोग करके टेबल में रिकॉर्ड डालें:
mysql> insert into DemoTable values(101,'Chris',26); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(102,'Robert',27); Query OK, 1 row affected (0.16 sec)
सेलेक्ट स्टेटमेंट का उपयोग करके टेबल से सभी रिकॉर्ड प्रदर्शित करें:
mysql> select * from DemoTable;
इससे निम्न आउटपुट प्राप्त होगा:
+------------+--------------+-------------+ | CustomerId | CustomerName | CustomerAge | +------------+--------------+-------------+ | 101 | Chris | 26 | | 102 | Robert | 27 | +------------+--------------+-------------+ 2 rows in set (0.00 sec)
सभी कॉलम कॉनकैट करने का क्वेरी:
mysql> select concat(CustomerId,CustomerName,CustomerAge) from DemoTable;
इससे निम्न आउटपुट प्राप्त होगा:
+---------------------------------------------+ | concat(CustomerId,CustomerName,CustomerAge) | +---------------------------------------------+ | 101Chris26 | | 102Robert27 | +---------------------------------------------+ 2 rows in set (0.00 sec)