This is my Rows in a table :
Id | FromDate | ToDate | prod_Id ------|---------------------------|--------------------------|------- 1 | 2012-08-13 07:00:00.000 | 2012-08-14 18:59:00.000 | 10 1 | 2012-08-13 07:00:00.000 | 2012-08-15 18:59:00.000 | 10 1 | 2012-08-13 07:00:00.000 | 2012-08-16 18:59:00.000 | 10
I would like a result like below:
Id | FromDate | ToDate | prod_Id ----|-----------------------------|---------------------------|--------- 1 | 2012-08-13 07:00:00.000 | 2012-08-16 18:59:00.000 | 10
How to do it?
SELECT Id, MIN(FromDate), MAX(ToDate), prod_Id
FROM TbName
GROUP BY Id, prod_Id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With