I'm getting an exception when trying to run my code, I'm fairly new to SQL not sure if I've used the right syntax.
"Column 'news.score' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause." System.Data.SqlClient.SqlException
foreach(PatientModel a in patientList)
{
try
{
con.Open();
cmd.CommandText = "SELECT MAX(datetime), score FROM news WHERE(patientID = @patientID)";
cmd.Parameters.AddWithValue("@patientID", a.PatientID);
reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("");
a.Score = (int)reader["score"];
}
}
catch
{
con.Close();
}
}
con.Close();```