Issue
I want to query & filter the table objectDetails for user 1,2,3 (We will get rows with id: 1,2,3,4,5). If status is 3 for shared Object then it should discard the row whose status is less than 3 (Here row with id 4 & 5 should be discarded). Here we should get the row with id 1,2,3 as output.
Here is the table: objectDetails : Object can be shared by multple user. Status can be between 1 to 3.
id, Object , user, status
1 , 00110 , 1 , 1
2 , 00111 , 2 , 2
3 , 00112 , 3 , 3
4 , 00112 , 1 , 1
5 , 00112 , 2 , 2
6 , 00113 , 4 , 1
7 , 00114 , 5 , 2
Solution
Here i have filtered the data for the user & grouped the object which is shared across user. Then taken out the max status in the grouped data of object for the user.
Select id, max(status) as status from objectDetails where user in (1,2,3) GROUP BY object;
Answered By – RCS
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0