尝试在查询中连接3个表会返回空结果。奇怪的是,删除一个表(两个表连接)返回一些集。这是我的工作:
String sql = "SELECT\n" +
" tc.constraint_name, tc.table_name, kcu.column_name, \n" +
" ccu.table_name AS foreign_table_name,\n" +
" ccu.column_name AS foreign_column_name, constraint_type \n" +
"FROM \n" +
" information_schema.table_constraints AS tc \n" +
" JOIN information_schema.key_column_usage AS kcu\n" +
" ON tc.constraint_name = kcu.constraint_name\n" +
" JOIN information_schema.constraint_column_usage AS ccu\n" +
" ON ccu.constraint_name = tc.constraint_name\n" +
"WHERE constraint_type = 'FOREIGN KEY'";
List<Map<String, Object>> foreignTable1 = jdbcTemplate(getShardId(sku)).queryForList(sql);
总会返回一个空集。
答案 0 :(得分:0)
尝试使用外连接并检查是否存在没有相应ID的行,以便连接删除不匹配的行。特别是你写的,两个表导致非空结果集似乎表明,与第三个表的连接不会导致前两个结果集的匹配行。