Is it possible to group a table based on the condition in MYSQL?
I have table 'request' and I need to somehow group the table where the flag 'is_applicant' = 1 if exiting rows with the same 'id_request' and 'the same id_user' you can see it better by example...
I need to get this...
Thank you for the answer or advice how to achieve this, I need it to display the request to a specific user in php.
irl last edited by
SELECT id_request, MAX(is_applicant) AS is_applicant GROUP BY id_request ORDER BY id_request DESC
I left out id since it is probably irrelevant.
I left out id_user and id_status; perhaps you want
MAX(id_user)? The issue is, if there could be two users or two statuses, which one do you want?
If you do need
id, then see tag [greatest-n-per-group].