I've a table in a DB that looks like this:
TABLE `partecipanti` (
`ID` int(11) NOT NULL,
`Name` varchar(30) DEFAULT NULL,
`Surname` varchar(30) DEFAULT NULL,
`Score2` int(11) DEFAULT NULL,
`Zero1` int(11) DEFAULT '0',
`Zero2` int(11) DEFAULT '0',
`Score1` int(10) NOT NULL DEFAULT '0'
)
And a query that looks like this:
SELECT *,Score1 + Score2 as Total FROM partecipanti
ORDER BY Total DESC,Score2 DESC,Zero2 DESC,Score1 DESC, Zero1 DESC;
Now the thing I'd like to do is : when I've a duplicate record (same name and same surname while the other data including ID are differents) pick the row that has the higher score which is stored in the field Total
I was thinking about a nested query,in the first query I order the data and I group them with GROUP BY, then I select the higher element. Could anyone help me please? Thanks.
EDIT:
If I add the DISTINCT statement the query seems to work , is it ok? Thanks.