I have 10 fields in my table but i need 8 fields when i select , i dont want to specify select 1,2,3,4,5,6,7,8 from........
,
Any easy way to get the 8 fields (Other hand i dont want to select primary,unique key fields)
Asked
Active
Viewed 45 times
1 Answers
1
see the answer in this :
Select all columns except one in MySQL?
Actually there is a way, you need to have permissions of course for doing this ...
SET @sql = CONCAT('SELECT ', (SELECT REPLACE(GROUP_CONCAT(COLUMN_NAME), '<columns_to_delete>,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<table>' AND TABLE_SCHEMA = '<database>'), ' FROM <table>');
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
Replacing <table>, <database> and <columns_to_delete>