Reputation: 39
Okay I have a some code written to retrieve data from some left join in my database, after retrieving this data I use the id from each to populate a modal. The thing is it works for some of the data that has been retrieve. For when i look at the query result I notice the id's are null for some valid data an some or not
$someuser = DB::table('users')
->join('sometable', 'sometable.user_id', '=','users.id')
->leftjoin('sometable', 'users.id', '=', 'skills.user_id')
->leftjoin('sometable', 'users.id', '=','schools.user_id')
->leftjoin('sometable', 'users.id', '=', 'languages.user_id')
->leftjoin('sometable','users.id', '=', 'memberships.user_id')
->leftjoin('sometable', 'users.id', '=', 'convictions.user_id')
->leftjoin('sometable', 'users.id', '=', 'work_experiences.user_id')
->select('users.*','sometable.name as sometablename','sometable.*')
->where('users.first_name', '<>', '')->whereNotNull('users.id')
->orderBy('sometable.updated_at', 'DESC')->groupby('users.first-name')->distinct()->paginate(100);
from that, the query result looks like:
{"total":966,"per_page":100,"current_page":1,"last_page":10,"from":1,"to":100,"data":[{"id":null, etc
What am simple saying why is my id null
I think its not showing me no ids over 1900 so if a user is over 1900 it showing me null
Upvotes: 1
Views: 1408
Reputation: 33048
You are selecting *
from multiple tables. Since you are also left joining, it's very likely there is nothing to join on so your database is returning those columns as null. Specifically select the id you need and alias it as something which will not be overwritten by another column.
Upvotes: 2