【发布时间】:2012-02-09 12:16:45
【问题描述】:
嗨,我正在使用 codeigniter,我有一张这样的表
我想获取PreferenceID 值不在PreferenceParentID 列中的所有记录
在这种情况下,我也在使用 EntityID 进行调整。 PreferenceParentID 应该是 != 0
假设我按entityID 53 过滤
我的结果应该是
Couture , Denims
因为PreferenceID 在这两种情况下都不在PreferenceParentID 中。我试过where_not_in(),但做不到。请帮忙
这是我的查询
$table = $this->mastables['shop_profile_preferences'];
$this->db->select('a.ProfilePreferenceID');
$this->db->from($table." as a");
$where2 = "(SELECT a.PreferenceParentID FROM ".$table.")";
$this->db->where_not_in('a.PreferenceID', $where2);
$this->db->where("a.EntityID",$shop_id);
$this->db->where('a.PreferenceParentID !=',0);
$query=$this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
else
{
return FALSE;
}
我的查询结果是
Array
(
[0] => Array
(
[ProfilePreferenceID] => 274
)
[1] => Array
(
[ProfilePreferenceID] => 275
)
[2] => Array
(
[ProfilePreferenceID] => 276
)
)
如何正确使用where_not_in()。或 ids 有任何其他方法。请帮忙 .....
在此先感谢。
更新
$table = $this->mastables['shop_profile_preferences'];
$this->db->select('a.ProfilePreferenceID,a.ProfilePreferenceValue');
$this->db->from($table." as a");
$this->db->where('a.PreferenceParentID !=',0);
$this->db->where('a.PreferenceID NOT IN (SELECT a.PreferenceParentID FROM '.$table.')', NULL, FALSE);
$this->db->where("a.EntityID",$shop_id);
$query=$this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
else
{
return FALSE;
}
【问题讨论】:
标签: php mysql codeigniter