Skip to content

Instantly share code, notes, and snippets.

@ivanrosolen
Created June 1, 2016 15:26
Show Gist options
  • Select an option

  • Save ivanrosolen/af5f0e95ede8d7ff879bb38df10458a6 to your computer and use it in GitHub Desktop.

Select an option

Save ivanrosolen/af5f0e95ede8d7ff879bb38df10458a6 to your computer and use it in GitHub Desktop.
Use column names as select fields in another mysql query
SELECT group_concat(distinct column_name) as fields
FROM information_schema.columns
WHERE table_name='table_name' and column_name like 'text%' INTO @COLUMNS;
SET @s = CONCAT('SELECT ',@COLUMNS,' FROM table_name limit 10');
PREPARE stmt FROM @s;
EXECUTE stmt;
-- DEALLOCATE PREPARE stmt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment