List:General Discussion« Previous MessageNext Message »
From:Shawn Green Date:February 8 2010 7:07pm
Subject:Re: how to get distinct values in the following scenarion
View as plain text  
MuraliKrishna wrote:
> Hi
> 
> I have table like as following..
> 
>  
> 
> 
> Cust_id
> 
> Visited_date
> 
> 
> 1
> 
> 2-1-2010
> 
> 
> 2
> 
> 3-1-2010
> 
> 
> 3
> 
> 4-1-2010
> 
> 
> 4
> 
> 5-1-2010
> 
> 
> 6
> 
> 6-1-2010
> 
> 
> 1
> 
> 7-1-2010
> 
> 
> 2
> 
> 8-1-2010
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> These visitor ids with visited date. but I want only all the customers with
> first visited date.
> 
> Please help me in this..
> 

So you want to see only the earliest date for each visitor? Try a query 
that looks like this:

SELECT  visitor_id, min(visit_date) from ... GROUP BY visitor_id;


The details behind this kind of query are available from many, many 
sources. Here's one from our manual:

http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html
(in your case, you are using MIN() instead of COUNT() )

The full list of GROUP BY Functions are here:
http://dev.mysql.com/doc/refman/5.1/en/group-by-functions-and-modifiers.html

-- 
Shawn Green, MySQL Senior Support Engineer
Sun Microsystems, Inc.
Office: Blountville, TN


Thread
how to get distinct values in the following scenarionMuraliKrishna6 Feb
  • Re: how to get distinct values in the following scenarionShawn Green8 Feb