gpt4 book ai didi

php - Yii ActiveRecord : select only first row with the same value

转载 作者:行者123 更新时间:2023-11-30 00:22:10 25 4
gpt4 key购买 nike

假设我有下表:(id, subject_id),在该表中我有以下记录:

id: 1, subject_id: 1id: 2, subject_id: 1id: 3, subject_id: 2id: 4, subject_id: 1id: 5, subject_id: 2

如何仅获取 subject_id = 1 的第一行和 subject_id = 2 的第一行:

id: 1, subject_id: 1id: 3, subject_id: 2

最佳答案

当您使用 group by 时,只会获取第一条记录。

$criteria = new CDbCriteria;
$criteria->group = 'subject_id';
$models = YouModelName::model()->findAll($criteria);

关于php - Yii ActiveRecord : select only first row with the same value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23147556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com