I have a table which have three fields ID,Name,aDate. I want result on distinct name and i want date to be in result. I am using query as
Select distinct(Name),adate from table_name.
But i am getting wrong results.i think sql is appling distinct on combination of both fields. What i do help me. I want distinct name values with their respective adate field.
If you only want ONE Date per Name then you have to specify which date:
Eg:
Since this statement uses
GROUP BY Nameit will only return one row for each Name. Since it uses an aggregation of aDate (in my example theMAX()function) it will return the appropriate date which you want.In general you should try to avoid the use of the DISTINCT keyword. It is seldom the right approach.
If you simply want the list of distinct names used in your table you can use
which will return the same results as