【发布时间】:2014-09-26 06:56:03
【问题描述】:
我有两个表 store(id,name,date) 和 store_services(id,store_id,name,price,date) 我已经通过 price 实现了搜索过滤器,我想在我的页面中显示唯一的商店记录。 但我仍然从存储表中获取重复记录。
通过 distinct(store_services.store_id) 在 mysql 查询中运行良好 但它不适用于 Yii CDbCriteria。 我的 Mysql 查询是:
SELECT DISTINCT(store_services.store_id),store.id,store.name,store.date FROM store INNER JOIN store_services ON store.id = store_services.store_id WHERE store_service.price BETWEEN 1,1000
请给我一个 Yii 不同记录的代码 注意: 我在 Yii 中使用 $criteria->distinct=true;
但它也得到重复记录
【问题讨论】:
-
删除 Distinct 并尝试在同一列上使用 group by,例如
$criteria->group = 'store_id'; -
我建议在这里粘贴代码,确保您使用的是 findAll();
-
我用我的完整代码来回答。你想看看。