不等于条件不能在我的codeigniter的SQL查询中工作。 我也试过<>但这也没有用,请一些人帮忙解决这个问题。 输出显示等于条件
$result = $this->db->query("select a.user_email from users as a, result as b where b.exam_id = '".$exam_id."' and a.user_id != b.user_id and a.active = 1 and a.user_role_id != 1 group by a.user_id")
->result();
答案 0 :(得分:1)
尝试使用此功能,因为编译器无法清楚地理解查询是否会导致输出错误。
$query="select a.user_email "
. "from users as a, result as b "
. "where b.exam_id = '".$exam_id."'"
."a.active = 1 and"
. "(a.user_id != b.user_id) "
. "and "
. "(a.user_role_id != 1 group by a.user_id)"
答案 1 :(得分:0)
非常感谢你的建议。这是正确的查询
select * from users
where user_id not in (select user_id from result where exam_id = '".$exam_id."') and active = 1 and user_role_id != 1