Dear All I have this table as shown below
| ID | Student_Name | Marks | Course_ID |
| 1 | ABC | 78 | 1 |
| 2 | HHH | 88 | 3 |
| 3 | ABC | 89 | 1 |
| 4 | ABC | 99 | 1 |
| 5 | CCC | 67 | 2 |
| 6 | HHH | 76 | 3 |
From above table I would like to get the records I would like to take one record for each course ID but that records must be the latest one for that course ID like for course ID =1 the record I need to get should have ID =4 as this is the latest for course _ID 1 , same as for HHH I need to get row 6 and 6 is the latest record this is auto increament Id , and for CCC as there is only one record so I need to get 5th row, how to get this in linq query
Sachin SinghPosted Jan 18, 2024, 7:16 AM
@Pakeeza it is even simpler in LINQ
PakeezaPosted Jan 18, 2024, 7:46 AM
Dear both Uttam Chaturvedi,Sachin Singh the query Linq works as the SQL for this is provided by Uttam Chaturvedi so should I mark him even though you translated it into Linq there is no option to mark two as correct.
PakeezaPosted Jan 18, 2024, 7:10 AM
Uttam Chaturvedi can you share in LINQ
Amit MohantyPosted Jan 18, 2024, 6:05 AM
Check this:
PakeezaPosted Jan 18, 2024, 5:47 AM
I need this in Linq in SQL I did it thanks for the help
Uttam ChaturvediPosted Jan 17, 2024, 10:41 PM
Here you go with sql query to get latest records by id. Assuming your table name is student
SELECT * FROM dbo.student
WHERE id IN
(SELECT MAX(id) FROM dbo.student GROUP BY student_name)
Please accept answer, if you find it useful