Okay the title may not justify what I'm trying to do here but dont know my problem well enough to explain it perfectly.
What i'm trying to do:
I need to retrieve rows from a MySQL data base where response = 8 or 9 but display the newest entry if there are multiple matches. Let say I have 6 rows and 1 rows have response = 8 and 2 row where response = 9 I want to retrieve the newest entry based on row id.
example:
row1 id=12 user_id = 15 response = 8
row2 id=11 user_id = 15 response = 9
row3 id=10 user_id = 15 response = 1
row4 id=09 user_id = 15 response = 9
row5 id=08 user_id = 15 response = 4
row6 id=07 user_id = 15 response = 5
I want to retrieve row1 since it's the newest entry where response = 8 or 9
I tried but failed:
SELECT a.id, MAX(a.response) FROM user a WHERE a.user_id = $userID AND a.response IN (8,9) GROUP BY a.user_id
Thanks in advanced.