Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL minimum date query

Author  Topic 

ranvir_2k
Posting Yak Master

180 Posts

Posted - 2014-10-13 : 12:04:51
Hi all,

I have a table with data like the following:


ClientID InvoiceDate
1 2012-01-01
1 2013-01-01
2 2012-01-01
2 2013-01-01
3 2012-01-01
3 2013-01-01

I would like to return a distinct ClientID and also the minimum InvoiceDate for that ClientID, so that the data looks like this:


ClientID InvoiceDate
1 2012-01-01
2 2012-01-01
3 2012-01-01

Can you tell me what query I will need to write to achieve this.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-13 : 12:08:36
This sure looks like a homework question, but I'm confused by your number of posts.

select ClientID, MIN(InvoiceDate) as InvoiceDate
from yourtable
group by ClientID

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -