I have a table in my db that looks like this:
Col 1 | Col 2 |
---|---|
John | 230601 |
Frank | 230601 |
Tom | 230604 |
Bill | 230604 |
Tina | 230604 |
Leroy | 230602 |
Ernie | 230601 |
Sue | 230601 |
I want to get all rows with the max col2 value. (in this case max value is 230604 and it would be Tom, Bill and Tina).
I tried the below which failed:
$data = DB::table($table)->where('col2','=','(SELECT max(col2) from '.$table.')')->get($fields);
2
Answers
This should do
You can use
Model::max("col2");