SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s) (SQL: select * from `lastmes` where id IN (select MAX(`id`) as id,peer_id from `lastmes` group by `peer_id`) order by `id` desc limit 10)
$subQuery = DB::table('lastmes')
->select(DB::raw('MAX(`id`) as id'))->groupBy('peer_id');
$res = DB::table('lastmes')
->whereRaw('id IN (' .$subQuery->toSql().')')
->orderBy('id','desc')
->limit('10')
->get();
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select MAX(`id`) as id,peer_id from `lastmes` group by `peer_id` order by `id` d' at line 1 (SQL: select * from `lastmes` where id IN select MAX(`id`) as id,peer_id from `lastmes` group by `peer_id` order by `id` desc limit 10)
$subQuery = DB::table('lastmes')
->select(DB::raw('MAX(`id`) as id,peer_id'))->groupBy('peer_id');
$res = DB::table('lastmes')
->whereRaw('id IN' .$subQuery->toSql())
->orderBy('id','desc')
->limit('10')
->get();
$res = DB::table('lastmes')
->select(DB::raw('MAX(id) as id, peer_id, data'))
->groupBy('peer_id')
->orderBy('id','desc')
->limit('10')
->get();