0

我收到以下错误。

Error Code: 1060. Duplicate column name 'app_id'

只有当我尝试包含所有结果时才会发生这种情况(因为有两个 app_id)。我可以通过指定哪个表或执行“application.*”从 key_table 中排除 app_id。

application.* 的唯一问题是存在一个不受 ENGINE=MEMORY 支持的文本字段。MySQL 通常在引用“”时忽略此文本字段,但在引用“tablename. ”时不会。

有人可以给我一个简单的解决方案吗?

CREATE TEMPORARY TABLE pparsreporting.CurrentApplications ENGINE=MEMORY
(
SELECT *, getApplicationsForRespID.app_id2 AS app_id2,
planning_scheme.markus_ra, planning_scheme.metro_or_rural

FROM application
INNER JOIN key_table ON key_table.app_id = application.app_id
INNER JOIN planning_scheme ON planning_scheme.ps_code = application.planning_scheme

CROSS JOIN 
(
    SELECT key_table.app_id AS app_id2, planning_return.resp_authority AS resp_id
    FROM key_table
    INNER JOIN planning_return ON key_table.return_id = planning_return.return_id

)getApplicationsForRespID

WHERE application.app_id = getApplicationsForRespID.app_id2
AND key_table.is_current = 1

);

SELECT * FROM pparsreporting.CurrentApplications

4

1 回答 1

0

我不得不遍历每个表名并排除我不想要的那个。我知道很乱,但它有效。

String EachTable = "";
    Statement GetTableNames = mDatabaseConnection.createStatement();
    ResultSet rs = GetTableNames.executeQuery("SELECT * FROM pparsdb.application LIMIT 1");
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    // The column count starts from 1
    for (int i = 1; i < columnCount + 1; i++ ) 
    {
        EachTable += ",application." + rsmd.getColumnName(i);
    }

    System.out.println(EachTable);
于 2013-05-31T04:18:35.620 回答