Here is the table
table: StudentHistory
id | date | name | grade | subject
---- | ------ |------ |--------|------
1 | 5/1/2017 |Mark | a | science
2 | 7/1/2016 |Earl | c | english
3 | 2/1/2015 |John | a | english
4 | 6/1/2016 |Mike | c | science
5 | 4/1/2016 |Matt | e | english
6 | 2/1/2017 |Mark | d | science
7 | 3/1/2016 |Earl | a | english
8 | 7/1/2015 |John | d | english
9 | 8/1/2016 |Mike | c | science
What I want to happen is to populate the latest grades ONLY in English for students who have one. It should show like this
7/1/2016 Earl c
7/1/2015 John d
4/1/2016 Matt e
I got this but it doesn't give the latest based on
$englishgrades = StudentHistory::('date', 'name', 'grade')
->where('subject', 'english')
->groupBy('name')
->get();
Please help
I don't know what you mean by 'populate' in this context, and I don't know laravel; but here's a query that gets the desired result...
You can do descending order and receive first row which is going to be your last row in database. But the thing is you store date in a wrong way. as mentioned by @Strawberry its not clear date or month. I would suggest you to do use mysql datetime option then you can simply do the code I post below. In this case you might have to parse each date for a proper way