user6576015 user6576015 - 4 months ago 20
SQL Question

SQL Server 2008 : SELECT min(date)

I'm trying to do a simple select statement but I'm having a hard time doing it.

I have a table with these columns:

companyID, CompanyDept, DateAdded


I'm trying to do a select statement like this...

Select CompanyID, CompanyDept
where min(dateAdded)


So there are multiple dates for
DateAdded
- I'm trying to select the
CompanyDept
and
COmpanyID
by the earliest
DateAdded
.

EDIT: Select CompanyID, CompanyDEpt where dateAdded=MIN so because there might be three or more dates such as 10/1/2015, 11/12/2015, 1/4/2016 -(rows of data i mean) I'm trying to select this date looking at the earliest possible date (10/1/2016)

Answer

You can try just getting the first record using TOP 1 and ordering by date.

SELECT TOP 1
    CompanyID, CompanyDept
FROM 
    Table
ORDER BY 
    dateAdded