开发者

Select all fields other than those listed? [duplicate]

This question already has answers here: 开发者_运维百科 Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜