简体   繁体   中英

fetching field in laravel query

I have two tables user_master and user_teams with common field user_name. I want to join the table and get the team value group by teams tried as

$filter_teams = DB::table('user_teams')
->join('user_master','user_master.user_name','=','user_teams.user_name')
->whereIn('user_master.geo',$geo)
->groupBy('user_teams.team')
->pluck('user_teams.team')
->toArray();

by may values are duplicating.I'm using postgresql

since you didn't determine select fields... the default will be '*' this is why you are getting duplicated fields...

just add:

->select('user_teams.team') 

and i think that all.

i recommend not using group without aggregation.... so my advice your query to like this:

$filter_teams = DB::table('user_teams')
->join('user_master','user_master.user_name','=','user_teams.user_name')
->whereIn('user_master.geo',$geo)
->select('user_teams.team')->distinct()
->pluck('user_teams.team')
->toArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM