Query to list columns from particular table of the particular database in MySQL:
1. Get the list of columns as multiple rows:
2. Get the list of columns as a single concatenated string:
1. Get the list of columns as multiple rows:
SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='database_name' AND `TABLE_NAME`='table_or_view_name';
2. Get the list of columns as a single concatenated string:
SELECT GROUP_CONCAT(`COLUMN_NAME` SEPARATOR ',') FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='database_name' AND `TABLE_NAME`='table_or_view_name';
No comments:
Post a Comment
Please post any queries and comments here.