Created
October 23, 2020 11:54
-
-
Save kouk/284b12c9e8fa7b4cb270e643319a0439 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @COLS = ''; | |
SELECT GROUP_CONCAT( COLUMN_NAME SEPARATOR ',') | |
INTO @COLS | |
FROM INFORMATION_SCHEMA.COLUMNS | |
WHERE COLUMN_KEY != 'PRI' | |
AND TABLE_NAME='mytable' | |
AND TABLE_SCHEMA = 'mydatabase'; | |
SET @SQL = CONCAT('SELECT ', @COLS, ' FROM mytable'); | |
PREPARE stmt FROM @SQL; | |
EXECUTE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment