I have a table in mssql (2005) which has four date columns in it and an ID column.
I would like to return the minimum date of all four columns and the associated id.
SELECT TOP 1 min(date1), min(date2), min(date3), min(date4) FROM datatable
WHERE date1 > CAST(? AS DATETIME) OR
date2 > CAST(? AS DATETIME) OR
date3 > CAST(? AS DATETIME) OR
date4 > CAST(? AS DATETIME)
I'm then sorting the dates in php to give me the mimimum row. I can't work out how to add returning the id to this.