Reputation: 4082
I got a MySQL tablw which will store the contest participant informations.
Structure like
id + user_id + marks + date_added
-----+--------------+-------------+----------------------
1 | 24 | 30 | 2014-02-06 03:04:08
-----+--------------+-------------+----------------------
1 | 25 | 10 | 2014-02-06 13:04:08
-----+--------------+-------------+----------------------
1 | 26 | 14 | 2014-02-06 05:04:08
-----+--------------+-------------+----------------------
1 | 27 | 54 | 2014-02-06 21:04:08
From this I need to find out a winner .
ie the winner with maximum marks. In case of multiple candidate with max marks then it will be on first come basis.
Got many contest with thousands of datas
Can anyone please show me a hint ?
Thanks in advance
Upvotes: 3
Views: 22237
Reputation: 1372
SELECT
user_id
FROM
`table name`
ORDER BY
marks DESC, date_added ASC
LIMIT
1
Replace table name
though.
Upvotes: 14