skip to Main Content

sql query last_messages displays wrong message – Laravel

i have query like this, but displays wrong last_message. $users = Message::join('users', function ($join) { $join->on('messages.from_id', '=', 'users.id') ->orOn('messages.to_id', '=', 'users.id'); }) ->where(function ($q) { $q->where('messages.from_id', auth()->user()->id) ->orWhere('messages.to_id', auth()->user()->id); }) ->where('users.id','!=',auth()->user()->id) ->select([ 'users.id', 'users.name', 'users.avatar', DB::raw('MAX(messages.created_at) max_created_at'), DB::raw('MAX(messages.body) last_message'), DB::raw('CASE…

VIEW QUESTION

PostgreSQL percentile

Let's say I have two tables called schools and students which have a one-to-many relationship. Each student can only be in one school but each school can have many students. school ----------- id name student ----------- id name school_id I…

VIEW QUESTION
Back To Top
Search