-1

我想选择尚未发布工作的用户。

我试过这个:

SELECT 
    e.id, e.companyName, ee.emailAddress, ee.firstName, ee.surname    
FROM 
    employer as e, country as country, employerUser as ee , countryRegion as re, job as j 
WHERE 
    country.iso2=e.countryISO2FK AND ee.employerIDFK=e.id AND ee.originalUser=1 AND country.iso2='GB' AND (e.regionCodeFK ='GTL' AND e.regionCodeFK = re.code OR e.regionCodeFK ='' OR e.city ='' ) AND e.status=1 AND e.isActive=1 AND e.id=j.employerIDFK AND j.employerIDFK IS NULL

有谁知道我做错了什么?

4

1 回答 1

2

您正在使用带有过滤器的CROSS JOINWHERE,它不会让您找到不存在的项目。您要使用的是“作业”表上的LEFT JOIN ,如下所示:

SELECT e.id, e.companyName, ee.emailAddress, ee.firstName, ee.surname 
FROM employer as e
  JOIN country ON country.iso2=e.countryISO2FK
  JOIN employerUser as ee ON ee.employerIDFK=e.id
  LEFT JOIN job as j ON e.id=j.employerIDFK 
WHERE ee.originalUser=1 
  AND country.iso2='GB' 
  AND (e.regionCodeFK ='GTL' AND e.regionCodeFK = re.code OR e.regionCodeFK ='' OR e.city ='' ) 
  AND e.status=1 AND e.isActive=1  
  AND j.employerIDFK IS NULL
于 2012-12-31T23:29:56.843 回答