我收到以下错误。
Error Code: 1060. Duplicate column name 'app_id'
只有当我尝试包含所有结果时才会发生(因为有两个app_id)。我可以通过指定哪个表或执行“application。*”来从key_table中排除app_id。
仅应用程序问题。*是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
答案 0 :(得分: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);