-1

For example, there is 10 fields in a table. I want to select 9 fields except one(a9).

a1 a2 a3 a4 a5 a6 a7 a8 a9 a10


select a1,a2,a3,a4,a5,a6,a7,a8,a10
from t1 

Is there simple way to get the result?

Notice: there is no rules for fields(like aN ). It's just convenient to make an example.

Jack
  • 1,724
  • 4
  • 18
  • 33

1 Answers1

0
SET @SQL = CONCAT('SELECT ', (SELECT GROUP_CONCAT(CONCAT("`", COLUMN_NAME, "`")) 
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 't1' 
AND COLUMN_NAME NOT IN ('a9')), ' FROM t1'); 
PREPARE stmt1 FROM @SQL; 
EXECUTE stmt1;
RAHUL JAIN
  • 11
  • 2