选择除MySQL中的一列以外的所有列? [英] Select all columns except one in MySQL?
本文介绍了选择除MySQL中的一列以外的所有列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用select语句从某个MySQL表中获取除一个以外的所有列.有没有简单的方法可以做到这一点?
I'm trying to use a select statement to get all of the columns from a certain MySQL table except one. Is there a simple way to do this?
此表中有53列(不是我的设计)
There are 53 columns in this table (NOT MY DESIGN)
推荐答案
实际上,有一种方法,您当然需要具有执行此操作的权限...
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_omit>,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<table>' AND TABLE_SCHEMA = '<database>'), ' FROM <table>');
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
替换<table>, <database> and <columns_to_omit>
这篇关于选择除MySQL中的一列以外的所有列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文