Sunday, October 16, 2011

SQL to get unique entry and the date it was first entered

Let's say you have this table:

Email          EnteredDate
abc@abc.com    11/1/2011
xyz@zyx.com    11/1/2011
abc@abc.com    11/2/2011

and you want to get list of unique emails and the date when it was first entered. Then this query:

SELECT email, min(EnteredDate) as FirstEntered FROM entries
GROUP BY email

will give you this result displaying unique email with the date it was first entered:

Email          FirstEntered
abc@abc.com    11/1/2011
xyz@zyx.com    11/1/2011

If you know any better solution then please share it with me.

No comments:

Post a Comment