MySQL内部联接查询提供重复的结果

时间:2022-08-11 00:14:59

I have written a query using inner join which consist of multiple tables

我使用内连接编写了一个查询,该连接由多个表组成

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

The above query works but gives multiple results of the same record or duplicate records Please help me fix the query or provide with an alternative to this query also please suggest me ways to optimize the query for faster processing??

上面的查询工作,但给出了相同记录或重复记录的多个结果请帮我修复查询或提供替代此查询也请建议我优化查询的方法,以加快处理速度?

The above Query

以上查询

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

Below Given is the screen shot of the results.

下面给出的是结果的屏幕截图。

MySQL内部联接查询提供重复的结果

I want only one record per person and not duplicate records?

我想每人只有一条记录而不是重复记录?

Apart from that when i use foreach/while loop the results vary please help?

除此之外,当我使用foreach / while循环时,结果会有所不同请帮助吗?

1 个解决方案

#1


0  

Actually The problem was with gender table which had no reference in the query as soon as i removed the gender table inner join it worked as expected!

实际上问题是性别表,一旦我删除性别表内连接它没有参考,它按预期工作!

#1


0  

Actually The problem was with gender table which had no reference in the query as soon as i removed the gender table inner join it worked as expected!

实际上问题是性别表,一旦我删除性别表内连接它没有参考,它按预期工作!