0

I need to make a MySQL query where I don't want to select a column named description. Is there an easy way to specifically say to NOT select the column.

Example: I want to SELECT all but the description column. Can this be done or I have to write each one I need to pick instead?

id| Serverid | date_added | description ...
 1        yes   12.03.09     bad engine
 3        yes   12.04.09     ok engine
 2        no    12.05.09     ok engine
 4        yes   12.06.09     bad engine



$cars = lib::$db->GetAll("SELECT SQL_CALC_FOUND_ROWS
                c.*,
            FROM cars AS c
            ORDER c.date_added DESC
            LIMIT 10);
Dharman
  • 26,923
  • 21
  • 73
  • 125
mk81
  • 3
  • 8

2 Answers2

0
SET @sql = CONCAT('SELECT ', (SELECT REPLACE(GROUP_CONCAT(COLUMN1), '<Col To Omit>,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<TableName>' AND TABLE_SCHEMA = '<DBName>'), ' FROM <TableName>');

PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
Dharman
  • 26,923
  • 21
  • 73
  • 125
Shantun Parmar
  • 436
  • 2
  • 13
-1

No, there is no sane way to do that except listing all fields manually, like

SELECT id, Serverid, date_added FROM table

On a side note, with any sensible setup, there would be no difference in performance if you do SELECT *

Your Common Sense
  • 154,967
  • 38
  • 205
  • 325