I have table as
P_Id | userid | year | month | day
-----+--------+------+-------+------
3 | 3 | 2011 | 2 | 2
5 | 1 | 2011 | 2 | 3
16 | 8 | 2011 | 3 | 4
5 | 3 | 2011 | 4 | 4
17 | 1 | 2011 | 4 | 6
8 | 4 | 2011 | 7 | 7
9 | 3 | 2011 | 8 | 8
10 | 8 | 2011 | 9 | 9
I want to select distinct column i.e userid but also the respective value of year month and year which were encountered first.
For given above table following should be output
P_Id | userid | year | month | day
-----+--------+------+-------+------
3 | 3 | 2011 | 2 | 2
5 | 1 | 2011 | 2 | 3
16 | 8 | 2011 | 3 | 4
8 | 4 | 2011 | 7 | 7
or
If i am ordering the table by year,month and day
userid which is encountered first must only be selected and rest must be not be selected
Put year, month and day to native date column and do this:
It will provide the fastest result.
If you cant modify your table and should use year+month+day then you can convert this values to date and still use min function.