select u.username, t.title from user u join task t on u.id = t.id;其中 user u 是用来把表名简化 join则是加入其他的表 on则是表示查询的条件 u.username 则是表示user表中的username字段
select * from user u join task t on u.id = t.id join task_user tu on tu.id = t.id
$query = new Query(); $query->select('title,content,task.enable,task.id'); $query->from('task'); $query->leftJoin('task_user_rel', 'task.id= task_user_rel.task_id'); $query->leftJoin('user', 'task_user_rel.user_id = user.id'); $query->leftJoin('org_user_rel', 'user.id = org_user_rel.user_id'); $query->leftJoin('org', 'org_user_rel.org_id =org.id'); $query->where([ 'org.id' => $orgModel->id ]); $data = $query->all(); $data = $query->one();
$data = JdCrmSmsUserModel::find()->where([ 'vender_id' => [ $venderId ] ])->all();
原文地址:http://blog.csdn.net/linongcheng/article/details/39030467