a16s table
id p_id u_id time
1 1 2 0
2 1 1 1
3 1 5 2
4 1 6 3
5 1 7 4
6 2 2 2
7 2 3 1
8 2 1 0
9 3 2 11
10 3 4 8
11 3 8 15
I want to get the first two data orderby time from each group
p_id u_id time
1 2 0
1 1 1
2 1 0
2 3 1
3 4 8
3 2 11
I try the query
$result = DB::table('a16s')
->select ('p_id','u_id','time'))
->orderBy('time', 'desc')
->groupBy('p_id')
->get();
echo '<pre>' ;
print_r($result);
I got the error SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column...
Can I use groupby twice? I Want to get this result to use on the jquery datatable.
from the database
id p_id u_id approve time
1 1 1 1 1
2 1 2 1 2
3 1 3 1 3
4 1 4 0 4
5 1 5 0 5
6 2 1 0 1
7 2 2 1 2
8 2 5 0 3
9 2 6 0 4
10 3 2 1 1
11 3 5 1 2
12 3 8 1 3