Skip to content

Instantly share code, notes, and snippets.

@koras
Created December 1, 2018 17:18
Show Gist options
  • Save koras/af887a30d100b7843c5f9c6d81548ccb to your computer and use it in GitHub Desktop.
Save koras/af887a30d100b7843c5f9c6d81548ccb to your computer and use it in GitHub Desktop.
// (SQL: select (select `user`.`id` from `user` where `user`.`id` in (2013, 2015) limit 1)
// as ff from `user` as `tmp_user`
// where `tmp_user`.`year` in (?, ?))
public function arrayUser(){
$arrayUser = [5,6];
$arrayYear = [2013,2015];
$subSelect = DB::table('user')
->select('user.id')
->wherein('user.id',$arrayUser)
->limit(1)
->toSql();
DB::table('user as tmp_user')
->select( DB::raw('('.$subSelect.') as ff')
)
->wherein('tmp_user.year',$arrayYear)
->get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment