Posted By

imbraz on 06/24/14


Tagged

mysql select column


Versions (?)

Extract the column names of a table (so you can select many columns but exclude some)


 / Published in: MySQL
 

URL: http://www.sql-ex.ru/help/select20.php

This will get the names of all the columns as one long string ready to use in a select statement. N.B. There is a list of column names to exclude (In this case '???COLUMNSTOEXCLUDE???')

  1. SELECT GROUP_CONCAT(COLUMN_NAME)
  2. FROM INFORMATION_SCHEMA.COLUMNS
  3. WHERE TABLE_SCHEMA = '???MY_SCHEMA???' AND
  4. TABLE_NAME='???MYTABLE_NAME???' AND
  5. COLUMN_NAME NOT IN ('???COLUMNS_TO_EXCLUDE???')
  6. ORDER BY ORDINAL_POSITION;

Report this snippet  

You need to login to post a comment.