且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL-从多个表中显示列

更新时间:2023-01-29 16:54:54

从文档中获取版本5.0(

From the docs for version 5.0 (http://dev.mysql.com/doc/refman/5.0/en/show-columns.html)

"SHOW COLUMNS displays information about the columns in a given table" 

因此您不能真正在多个表上使用它.但是,如果您有information_schema数据库,则可以按如下方式使用它:

So you can't really use it on multiple tables. However if you have information_schema database then you could use it like follows:

select column_name 
from `information_schema`.`columns` 
where `table_schema` = 'mydb' and `table_name` in ('users', 'posts');

在这里,您必须将mydb替换为您的数据库名称,或者只使用DATABASE().

Here you'd have to replace the mydb with your database name, or just use DATABASE().