我有两个名为测试和结果的表。
- 如果考生注册,则将其插入测试表中。
- 如果考生完成了测试,则详细信息已插入到结果表中。
现在,我需要一个查询来比较两个表,并使用候选人 ID 填充未完成测试的详细信息候选项。我正在使用zend框架工作请指导我 我正在使用此代码,但它不起作用
$dbTableInfo = $this->getDbTable()->info();
$select->from(array(
'c1' => 'test'),
array('c1.candidate_id',
"CONCAT( c1.first_name,
' ',
c1.last_name ) AS full_name",
'c1.active',
'c1.sendlink',
'c1.date_added',
'c1.username',
'c1.date_modified',
'c1.test_id')
);
$select->joinLeft(array('re'=>'result'));
$select->where("c1.business_id='" . $cid . "' AND 'c1.candidate_id NOT IN(re.candidate_id)'");
$select->order('c1.candidate_id');
很
抱歉没有回答您的问题,但是您为什么不简单地使用带有鉴别器字段的单个表,例如称为类型,并以这种方式使用它:
- 如果考生注册,他将入类型设置为测试
- 如果候选人完成了测试,那么他的类型将更改为已完成
也许你忘了在joinLeft中指定条件?
来自Zend Docs:
LEFT JOIN with the joinLeft(table, condition, [columns]) 方法。都 包括左侧操作数表中的行,匹配 包括右操作数表,以及右操作数中的列 如果没有与左侧表匹配的行,则用 NULL 填充表。
在查询中,您既没有指定条件,也没有指定要返回的列。
例如,您可以像这样进行连接:
$select->from(array(
'c1' => 'test'),
array('c1.candidate_id',
"CONCAT( c1.first_name,
' ',
c1.last_name ) AS full_name",
'c1.active',
'c1.sendlink',
'c1.date_added',
'c1.username',
'c1.date_modified',
'c1.test_id')
);
$select->joinLeft(
array('re'=>'result'),
'"c1".candidate_id = "re".candidate_id',
"*"
);