如何在mysql中获取两个表的列名?

时间:2015-10-14 11:30:34

标签: mysql

我目前正在使用以下查询从单个mysql表中获取列名

SELECT COLUMN_NAME as column_name 
    FROM INFORMATION_SCHEMA.COLUMNS 
        WHERE TABLE_NAME = 'product' 
            AND COLUMN_NAME 
                NOT IN ('ean','jan','isbn','mpn','upc');

如何从多个表中获取列名?对于这种情况,有没有像JOIN这样的选项?

2 个答案:

答案 0 :(得分:0)

SELECT COLUMN_NAME as column_name 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE (TABLE_NAME = 'product' AND COLUMN_NAME NOT IN ('ean','jan','isbn','mpn','upc'))
   OR (TABLE_NAME = 'other_table' AND COLUMN_NAME NOT IN ('something_else'))

答案 1 :(得分:0)

使用以下查询

SELECT COLUMN_NAME as column_name 
    FROM INFORMATION_SCHEMA.COLUMNS 
        WHERE TABLE_NAME in ('product' , 'other table name')
            AND COLUMN_NAME 
                NOT IN ('ean','jan','isbn','mpn','upc');