我是MySQL的新手,我正在使用一个数据库系统,它有四个主表,如下所述:
此查询主要使用的表位于:
看起来相当简单吧?
我的查询的目的是获取OpportunityID为NULL的显式用户的所有BusinessID,一旦它具有那些BusinessID,我希望它在Business表中找到关联的BusinessName,并将该BusinessName与EmploymentOpportunity中的BusinessName(Business)相匹配表.
这是我执行该操作的查询.
SELECT EmploymentOpportunity.OpportunityID,Business,Description
FROM UserBusinessOpportunity,EmploymentOpportunity
WHERE UserBusinessOpportunity.BusinessID =
(SELECT UserBusinessOpportunity.BusinessID
FROM UserBusinessOpportunity
WHERE UserBusinessOpportunity.UserID=1 AND
UserBusinessOpportunity.OpportunityID is NULL)
AND UserBusinessOpportunity.BusinessID = Business.BusinessID
AND Business.BusinessName = EmploymentOpportunity.Business;
sub-select语句应该返回BusinessID的子集.我确信这是一个非常简单的查询,但它一直给我重复的结果,我很确定为什么.结果集应该是3,但它发送给我24个,或者8个重复的那些3.
谢谢,如果你能帮我解决这个问题.
最佳答案