Select all fields other than those listed? [duplicate]
Possible Duplicate:
Select all columns except one in MySQL?
Hello,
SELECT field1, field2, field3 FROM table WHERE 1
this query will select field1
, field2
, filed3
How to selected all fields except field1
? Of course, we can tell to selected field2 and field3, but I'm talking about situation when there are a lot of such fields.
Thank you.
You can't define a dynamic list in a SELECT
clause, other than by using dynamic SQL.
set @qry = (select concat('select ',group_concat(column_name), ' from ' ,table_name) from
information_schema.columns
where table_schema = database()
and table_name = 'your_table'
and column_name <> 'field_you_want_to_exclude');
prepare stmt from @qry;
execute stmt;
deallocate prepare stmt;
You'll need to use information_schema.columns to generate a select query that includes all columns other than those you want to ignore, then execute the sql generated dynamically.
精彩评论