I have a following table.
ID Name State Date
1 A1 First 1/10/2013
2 A1 Second 1/11/2013
3 A1 Last 1/12/2013
4 A2 First 1/10/2013
5 A2 Closed 1/11/2013
6 A3 First 1/10/2012
7 A3 Second 1/10/2012
The order of preference of state is as follows
1 First
2 Second
3 Last
4 Closed
Which means that I have to display only the latest state of the Name (provided the state is not closed. In case the state is closed, I do not have to display that ID).
So the output of the above table should be
ID Name State Date
3 A1 Last 1/12/2013
7 A3 Second 1/10/2012
I’m not sure how to proceed? I would have tried something had I’d known but for now I’m struggling with it. I can do this in php and store the output in another table/view and display it but it has to be done in the database.
Thanks
Assuming that your
IDis auto_incremented.or if the datatype of column date is
DATE