联表查询


左连接

  1. User::where(['u.level' => 8])
  2. ->alias('u')
  3. ->join('user_info ui', 'u.id = ui.uid')
  4. ->fields('u.id, u.nickname, u.avatar, ui.name, ui.age')
  5. ->select();

右连接

  1. User::where(['u.level' => 8])
  2. ->alias('u')
  3. ->join('user_info ui', 'u.id = ui.uid', 'RIGHT')
  4. ->fields('u.id, u.nickname, u.avatar, ui.name, ui.age')
  5. ->select();

内连接

  1. User::where(['u.level' => 8])
  2. ->alias('u')
  3. ->join('user_info ui', 'u.id = ui.uid', 'INNER')
  4. ->fields('u.id, u.nickname, u.avatar, ui.name, ui.age')
  5. ->select();