Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a my sql table like the table below
CSS
id    visit_ date             Name
123   11/6/2015 3:17:22 PM    abc
123   11/6/2015 3:24:44 PM    abc
456   11/6/2015 3:26:34 PM    def
456   11/6/2015 3:30:34 PM    def


What I need to receive is

CSS
id             visit_ date             Name
677930136v     11/6/2015 3:24:44 PM    abc
906080275v     11/6/2015 3:30:34 PM    def


I have used DISTINCT id , visit date, name but it gives all the results.How can I select distinct values of id and name and the relevant visit date?
Posted
Updated 6-Nov-15 3:34am

1 solution

Try GROUP BY:
SQL
SELECT
    id,
    visit_date,
    Max(Name) As Name
FROM
    YourTable
GROUP BY
    id,
    visit_date
;
 
Share this answer
 
Comments
uglsa 6-Nov-15 9:49am    
It works Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900