我使用内连接编写了一个包含多个表的查询
SELECT *
FROM admin_info
INNER JOIN admin_login
INNER JOIN gender
INNER JOIN admin_type
INNER JOIN area
INNER JOIN document_type
INNER JOIN permissions
ON admin_login.admin_id=admin_info.admin_id
AND admin_type.admin_type_id=admin_info.admin_type_id
AND area.area_id=admin_info.area_id
AND document_type.document_id=admin_info.document_id
AND permissions.permission_id=admin_info.permission_id
上述查询有效,但会给出相同记录或重复记录的多个结果 请帮我修复查询或提供此查询的替代方法 还请建议我优化查询以便加快处理的方法??
以上查询
SELECT *
FROM admin_info
INNER JOIN admin_login
INNER JOIN gender
INNER JOIN admin_type
INNER JOIN area
INNER JOIN document_type
INNER JOIN permissions
ON admin_login.admin_id=admin_info.admin_id
AND admin_type.admin_type_id=admin_info.admin_type_id
AND area.area_id=admin_info.area_id
AND document_type.document_id=admin_info.document_id
AND permissions.permission_id=admin_info.permission_id
下面给出的是结果的屏幕截图。
我每个人只需要一条记录,而不是重复记录?
除此之外,当我使用foreach / while循环时,结果会有所不同请帮助吗?
答案 0 :(得分:0)
实际上问题出在性别表中,一旦我删除了性别表内部联接,它就没有参考查询!