Skip to content

Instantly share code, notes, and snippets.

@nitaking
Last active January 18, 2018 07:39
Show Gist options
  • Save nitaking/cf715378f3ab26308e03cd9191a1b7b1 to your computer and use it in GitHub Desktop.
Save nitaking/cf715378f3ab26308e03cd9191a1b7b1 to your computer and use it in GitHub Desktop.
[Eloquent]Union()で重複行があるのでdistinctしたい ref: https://qiita.com/nitaking/items/82fe97fffee9bef14b49
$first = DB::table('users')
->whereNull('first_name')
->get();
$users = DB::table('users')
->whereNull('last_name')
->get()
->union($first);
$first = DB::table('users')
->whereNull('first_name');
$users = DB::table('users')
->whereNull('last_name')
->union($first)
->get();
$first = DB::table('users')
->whereNull('first_name')
->get();
$users = DB::table('users')
->whereNull('last_name')
->get()
->union($first);
$first = DB::table('users')
->whereNull('first_name');
$users = DB::table('users')
->whereNull('last_name')
->union($first)
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment