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

Mysql – Allocation values from one row to another in SQL

I have the following table: CREATE TABLE table_one( person varchar(55), date_value date, proj varchar(2), value int, time varchar(2 ); INSERT INTO table_one VALUES ('A1',2020-10-01'W',10,'T1') ('A1',2020-10-01'A',5,'T2') ('A1',2020-10-01'P',6,'T3') ('A1',2020-10-01'A',9,'T4') ('A1',2020-10-01'P',11,'T5') ('A1',2020-10-01'A',4,'T6') ('A1',2020-10-01'P',2,'T7') ('A1',2020-10-01'A',1,'T8') ('A1',2020-10-01'P',10,'T9') ('A1',2020-10-01'A',8,'T10') I want an SQL query which creates…

VIEW QUESTION
Back To Top
Search